how to fix NaN value?

5 次查看(过去 30 天)
Suaad Al-Hussainan
% 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 个评论
Jan
Jan 2022-6-8
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
I got it now, thanks for helping me out Jan, I know I'm dumb sorry about that.

请先登录,再进行评论。

回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Deep Learning Toolbox 的更多信息

标签

产品


版本

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by