Neural Network toolbox. Training and testing the model
5 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Hi everyone. I have my input train and output train dataset which are 5184x3 and 5184x8. I am a new for all staff about neural network and etc. My output dataset colums values varies hugely i.e first coloums max value is 0.8 wherease seconds is 150.should I scale down the values to between 0 and 1? Actually, I want to construct network to predict the other values and I have additonally test data. However, I have a big error.
Here is my code:
T= xlsread("1data.xlsx");
intrain=T(1:5184,1:3);
outtrain=T(1:5184,4:11);
intest=T(5185:8640,1:3);
outtest=T(5185:8640,4:11);
net=feedforwadnet(10);
intrans=intrain';
outtrans=outtrain';
n=train(net,intrans,outtrans);
y=n(intrans);
yy=y';
error=outtrain(1,1)-yy(1,1);
0 Kommentare
Antworten (1)
Aditya
am 22 Jul. 2025
Hi Medet,
Absolutely, scaling your data is a crucial step when working with neural networks, especially when your output variables have significantly different ranges. If you do not scale your outputs, the neural network’s loss function will be dominated by the outputs with larger values, making it difficult for the network to learn the smaller-valued outputs effectively. This imbalance often leads to poor prediction accuracy and large errors, as you have observed.
To address this, it is recommended to normalize both your input and output data to a common range, typically [0, 1]. MATLAB provides the mapminmax function for this purpose. This function scales the data and also returns settings that can be used to reverse the scaling (i.e., to get predictions back to their original scale after the network has made its predictions).
Below is an example of how you can properly scale your data, train your neural network, and then reverse the scaling on the predictions:
% Read data
T = xlsread("1data.xlsx");
intrain = T(1:5184,1:3);
outtrain = T(1:5184,4:11);
intest = T(5185:8640,1:3);
outtest = T(5185:8640,4:11);
% Transpose for neural network toolbox
intrans = intrain';
outtrans = outtrain';
% Scale inputs and outputs to [0, 1]
[intransNorm, inSettings] = mapminmax(intrans, 0, 1);
[outtransNorm, outSettings] = mapminmax(outtrans, 0, 1);
% Create and train the neural network
net = feedforwardnet(10);
net = train(net, intransNorm, outtransNorm);
% Predict on training data (normalized)
yNorm = net(intransNorm);
% Reverse the scaling to get predictions in original scale
y = mapminmax('reverse', yNorm, outSettings);
yy = y';
% Calculate error on original scale
error = outtrain(1,1) - yy(1,1);
0 Kommentare
Siehe auch
Kategorien
Mehr zu Deep Learning Toolbox finden Sie in Help Center und File Exchange
Produkte
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!