Inputing Values to ANN Matlab model

조회 수: 16 (최근 30일)
Jack Durkacz
Jack Durkacz 2021년 2월 13일
댓글: ahtesham Khizer 2022년 9월 17일
I have been able to succesfully train my ann model. I now would like to give the ann model new inputs for it to predict the values. I can then compare the ANN prediction for this data set with the known. So far I have tried many options but dont seem to be getting the right answers. My code is below.
I have tried results = net(newinputs) and tried un normalising the results nut no joy. Am I barking up the wrong tree with this?
Thanks.
data = readmatrix('VAWT.csv');
x = data(:,1:4);
y = data(:,5)
m = length(y);
Visulisation of the data
histogram(x(:,4),10);
plot(x(:,4),y,'o')
Normalise the features and transform the output
y2 = log(abs(y+1));
for i = 1:4
x2(:,i) = (x(:,i)-min(x(:,i)))/(max(x(:,i))-min(x(:,i)))
end
histogram(x2(:,4),10);
plot(x2(:,1),y2,'o');
Train an Aritificial neural network (ANN)
xt = x2';
yt = y2';
hiddenLayerSize = 7;
net = fitnet(hiddenLayerSize);
net.divideParam.trainRatio = 70/100;
net.divideParam.valRatio = 30/100;
net.divideParam.testRatio = 0/100;
[net,tr] = train(net, xt, yt);
Performance of the ANN Network
yTrain = exp(net(xt(:,tr.trainInd)))-1;
yTrainTrue = exp(yt(tr.trainInd))-1;
sqrt(mean((yTrain - yTrainTrue).^2))
yVal = exp(net(xt(:,tr.valInd)))-1;
yValTrue = exp(yt(tr.valInd))-1;
sqrt(mean((yVal - yValTrue).^2))
Visualize the predictions from the ANN model
plot(yTrainTrue,yTrain,'x'); hold on;
plot(yValTrue,yVal,'o');
plot(0:40,0:40); hold off;
Optimize the number of neurons in the hidden layer
for i = 1:60
% defining the architecture of the ANN
hiddenLayerSize = i;
net = fitnet(hiddenLayerSize);
net.divideParam.trainRatio = 70/100;
net.divideParam.valRatio = 15/100;
net.divideParam.testRatio = 0/100;
% training the ANN
[net,tr] = train(net, xt, yt);
% determine the error of the ANN
yTrain = exp(net(xt(:,tr.trainInd)))-1;
yValTrue = exp(yt(tr.valInd))-1;
yTrainTrue = exp(yt(tr.trainInd))-1;
yVal = exp(net(xt(:,tr.valInd)))-1;
rmse_train(i) = sqrt(mean((yTrain - yTrainTrue).^2)) % RMSE of training
rmse_val(i) = sqrt(mean((yVal - yValTrue).^2)) % RMSE of validation set
end
Select the optimal number of Neurons in the hidden layer
plot(1:60,rmse_train); hold on;
plot(1:60,rmse_val); hold off;
  댓글 수: 1
ahtesham Khizer
ahtesham Khizer 2022년 9월 17일
Plz i also dont get the outputvalues by assigning input value plz mention command here thanks.

댓글을 달려면 로그인하십시오.

채택된 답변

Abhishek Gupta
Abhishek Gupta 2021년 2월 16일
Hi,
As per my understanding, you want to make predictions for new input using your trained network. You can do the same using the 'predict()' function in MATLAB as follows: -
YPred = predict(net,XTest);
For more information, refer to the following documentation link: -
  댓글 수: 1
Jack Durkacz
Jack Durkacz 2021년 2월 18일
Thank you. I have managed to solve the issue now.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

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