how to fix NaN value?

4 vues (au cours des 30 derniers jours)
Suaad Al-Hussainan
Suaad Al-Hussainan le 8 Juin 2022
% 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
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 Help Center et File Exchange

Tags

Produits


Version

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by