% Import Data
data = readmatrix('matrix 1.csv');
x = data(:,1:3);
y = data(:,4);
m = length(y);
% Visualization of data
histogram(x(:,3),10);
plot(x(:,3),y,'o');
% Normilize the features and transform the output
y2 = log(1+y);
for i = 1:3
x2(:,i) = (x(:,i)-min(x(:,i)))/(max(x(:,i))-min(x(:,i)));
end
histogram(x2(:,1),10);
% Train the Artificial Neural Network (ANN)
xt = x2';
yt = y2';
HiddenLayerSize = 10;
net = fitnet(HiddenLayerSize);
net.divideParam.trainRatio = 90/100;
net.divideParam.valRatio = 50/100;
net.divideParam.testRatio = 0/100;
[net,tr] = train(net, xt, yt);
% Preformance of the ANN network
yTrain = exp(net(xt(:,tr.trainInd)))-1; % GIVES NaN value
yTrainTrue = exp(yt(tr.trainInd))-1;
MSE = mean((yTrain - yTrainTrue).^2); %MSE gives NaN value
RMSE = sqrt(mean((yTrain - yTrainTrue).^2)); %RMSE gives NaN value
RealPercentageOfDestruction = exp(net(xt(:,tr.trainInd)))-1;%Real Percentage Of Destruction gives NaN value
yVal = exp(net(xt(:,tr.valInd)))-1; GIVES NaN value
yValTrue = exp(yt(tr.valInd))-1;
MSE1 = mean((yVal - yValTrue).^2); %MSE gives NaN value
RMSE1 = sqrt(mean((yVal - yValTrue).^2)); %RMSE gives NaN value

6 commentaires

KSSV
KSSV le 8 Juin 2022
Check the values of yVal, do they have NaN? We cannot test as the input data file is not given.
Suaad Al-Hussainan
Suaad Al-Hussainan le 8 Juin 2022
here is my input data file
KSSV
KSSV le 8 Juin 2022
Seriously? You got only data of size 5x4 and you want to run ML?
Suaad Al-Hussainan
Suaad Al-Hussainan le 8 Juin 2022
Is that the issue? I'm sorry, I'm not a coder, can you please help me understand?
Jan
Jan le 8 Juin 2022
The question is vague. Wheher do you observe NaN values? What does "fixing" mean?
data = [30, 9.6, 0, 61.7; ...
40, 9.6, 53.885, 58.6; ...
50, 9.6, 61.725, 55.7; ...
60, 9.6, 62.555, 60.4; ...
70, 9.6, 63.415, 54.4];
x = data(:,1:3);
for i = 1:3
x2(:,i) = (x(:,i)-min(x(:,i)))/(max(x(:,i))-min(x(:,i)));
end
The first NaNs appear here: for i=2, the max and min values are the same, so you divide by zero. How do you want to "fix" this? It is the correct result in a mathematical sense.
Suaad Al-Hussainan
Suaad Al-Hussainan le 8 Juin 2022
I got it now, thanks for helping me out Jan, I know I'm dumb sorry about that.

Connectez-vous pour commenter.

Réponses (0)

Catégories

En savoir plus sur Deep Learning Toolbox dans Centre d'aide et File Exchange

Produits

Version

R2022a

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by