How to plot graphs to analyze the ANN model?

7 次查看(过去 30 天)
Hi, am a newbie at this.
I have finished the codings for the ANN and my lecturer requested these graphs:
Predicted versus actual plot, MSE, MAE, MAPE: for the entire data set (training, testing, validation together) and separate ie. MSE training data set, MSE testing etc…
I am really not sure how to plot the graphs. I have already simulated the data, and have obtained the outputs (predicted data).
NO is the denormalized output data. T is the target data (to compare). Also, what does the code below mean? y2 is the predicted output and t2 is the target results.
y2=NO(2,:);%get the predicted outputs
t2=T(2,:);%get the target results
Could someone show me the codings for plotting the graphs as well as explain what the codes above mean?
Any help is appreciated!!!!

回答(1 个)

Raunak Gupta
Raunak Gupta 2020-3-19
Hi,
From the question I understand that you want to plot all the indices such as MSE (Mean Squared Error), MAE (Mean Absolute Error) and MAPE (Mean Absolute Percentage Error) for the dataset. I assume the plot are between these indices and epochs of training and you are using feedforwardnet as your ANN. Since it is required to have predicted values at epoch, you can mention the number of epochs to 1 by following
net.trainParam.epochs=1;
And calculated the indices with the predicted and actual value at each epoch in a for loop. Indices can be calculated easily by their definition. You can store the indices in an array which has size equal to number of epochs. Below example can be help get started.
% Lets say XTrain,XTest,XVal is Training,Testing and Validation data with
% sizes [n1,m], [n2,m], [n3,m] where n1,n2,n3 represent number of
% data-vectors in each set. Corresponding predicted value are YTrain,
% YTest, YVal with respective sizes.
% Lets assume m is 20 for example
% Num of Epochs = 100
numEpochs = 100;
net = feedforwardnet([10,20]);
net.trainParam.epochs=1;
MSETrain = zeros(1,numEpochs);
MSETest = zeros(1,numEpochs);
MSEVal = zeros(1,numEpochs);
MAETrain = zeros(1,numEpochs);
MAETest = zeros(1,numEpochs);
MAEVal = zeros(1,numEpochs);
MAPETrain = zeros(1,numEpochs);
MAPETest = zeros(1,numEpochs);
MAPEVal = zeros(1,numEpochs);
for i=1:numEpochs
net = train(net,XTrain,YTrain);
YPredictedTrain = net(XTrain);
YPredictedTest = net(XTest);
YPredictedVal = net(XVal);
MSETrain(i) = (1./(n1*m))*sum((YPredictedTrain-YTrain).^2,'all');
MSETest(i) = (1./(n2*m))*sum((YPredictedTest-YTest).^2,'all');
MSEVal(i) = (1./(n3*m))*sum((YPredictedVal-YVal).^2,'all');
MAETrain(i) = (1./(n1*m))*sum(abs(YPredictedTrain-YTrain),'all');
MAETest(i) = (1./(n2*m))*sum(abs(YPredictedTest-YTest),'all');
MAEVal(i) = (1./(n3*m))*sum(abs(YPredictedVal-YVal),'all');
MAPETrain(i) = (1./(n1*m))*sum(abs((YTrain-YPredictedTrain)./YTrain),'all');
MAPETest(i) = (1./(n2*m))*sum(abs((YTest-YPredictedTest)./YTest),'all');
MAPEVal(i) = (1./(n3*m))*sum(abs((YVal-YPredictedVal)./YVal),'all');
end
% All these errors can be plotted then with the help of plot

类别

Help CenterFile Exchange 中查找有关 Sequence and Numeric Feature Data Workflows 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by