I am unable to train a good performing model using NNTOOL

9 ビュー (過去 30 日間)
Ayushman Dam
Ayushman Dam 2023 年 4 月 19 日
回答済み: Ayush Aniket 2025 年 6 月 2 日
Hi, I have a total of 49 data points. Each has 4 coulmns in total, namely Speed, Compression Ratio, A/F ratio and Load. I wish to create a model by splitting this 49 datas into 35 and 14 sets to train andtest respectively.
Now till now after opening matlab i usuallydefine the input and target matrix being input = [
1700 8
1650 13
1700 13
1600 14
1450 10
1500 9
1500 10
1550 11 ]'; and target = [
6.841 6.742
6.877 10.467
6.937 9.859
7.127 10.72
6.996 10.5
6.886 9.4
6.998 10
7.161 10.553 ]';
I am not giving all 35 datas here as this is to make you understand. Now I import these into nntool and then creat a network where I choose Network type - Feed-forward backprop
input data and target data
Training Function - TRAINLM
Adaption Learning Function - LEARNGDM
Performance Function - MSE
Number of layers - 2
Layer 1 no. of neurons = 10 and transfer function = TANSIG
Layer 2 transfer function - PURELIN
After this I open the network to train where I chhose the input and target values. Epochs as default 1000 and max.
I am attaching my screen shots for your refernce. Kindly help me out as I need to be able to train better models for this limited data if possible

回答 (1 件)

Ayush Aniket
Ayush Aniket 2025 年 6 月 2 日
From the MSE graph image shared by you, it seems that the neural netowork is overfitting your training data. Since the whole process of training a neural network for a cusom dataset depends on a lot of heuristics, here are some suggestions that you should try out:
1. Data Preprocessing
  • Ensure that your input features (Speed, Compression Ratio, A/F ratio, Load) and target values are on similar scales. Differences in scale can cause the network to learn unevenly or converge slowly.Use functions like mapminmax or zscore for both inputs and targets.
  • If you normalize training data, make sure you apply the same normalization parameters to your test data—this keeps predictions consistent with the model training.
2. Data Splitting and Cross-Validation
  • A 35/14 split (roughly 70/30) is standard. However, with only 49 samples, any single split might not represent the data variability well. Consider using k-fold cross-validation (or even leave-one-out cross-validation). For example, a 5- or 7-fold cross-validation ensures each data point is used for testing exactly once, giving you a better estimate of model performance on unseen data.
3. Network Architecture and Complexity
  • With just 49 data points, using 10 neurons in a hidden layer might be more than necessary, as it can lead to overfitting. Start smaller (e.g., 5 neurons) and see if the performance is comparable.Experiment incrementally by adjusting the number of neurons and layers. Sometimes a simpler network generalizes better when data is scarce.
4. Training Function and Regularization
  • While TRAINLM is fast and effective for many problems, it may overfit on very small datasets.Consider trying Bayesian Regularization (trainbr), which adds a regularization term during training. Regularization helps prevent overfitting by penalizing large weights. You might need to adjust the performParam.regularization parameter of the network.
Although nntool is convenient, sometimes scripting with functions like crossvalind (from the Statistics and Machine Learning Toolbox) or by manually dividing your data can offer better control. Refer the script below that implements the above suggestions:
% Load your data (example matrices for illustration)
% X: 4 x 49 matrix containing [Speed; Compression Ratio; A/F ratio; Load]
% T: target data, e.g., 1 x 49 matrix
% Normalize the data
[X, ps_input] = mapminmax(X);
[T, ps_target] = mapminmax(T);
% Create a feedforward network with a smaller hidden layer
hiddenSizes = 5; % Adjust as needed to prevent overfitting
net = feedforwardnet(hiddenSizes, 'trainlm'); % You could try 'trainbr' here
% Specify data division parameters
net.divideFcn = 'dividerand';
net.divideParam.trainRatio = 0.7;
net.divideParam.valRatio = 0.15;
net.divideParam.testRatio = 0.15;
% Optionally, adjust training parameters like epochs if needed
net.trainParam.epochs = 1000;
net.trainParam.max_fail = 6; % For early stopping based on validation performance
% Train the network
[net, tr] = train(net, X, T);
% Test the network
Y = net(X);
Y_original = mapminmax('reverse', Y, ps_target);
% Assess performance using your preferred metrics
perf = perform(net, T, Y);

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by