Inputing Values to ANN Matlab model

4 ビュー (過去 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 Center および File ExchangeDeep Learning Toolbox についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by