Inputing Values to ANN Matlab model
14 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Jack Durkacz
el 13 de Feb. de 2021
Comentada: ahtesham Khizer
el 17 de Sept. de 2022
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 comentario
ahtesham Khizer
el 17 de Sept. de 2022
Plz i also dont get the outputvalues by assigning input value plz mention command here thanks.
Respuesta aceptada
Abhishek Gupta
el 16 de Feb. de 2021
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: -
Más respuestas (0)
Ver también
Categorías
Más información sobre Sequence and Numeric Feature Data Workflows en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!