how to fix NaN value?

조회 수: 4 (최근 30일)
Suaad Al-Hussainan
Suaad Al-Hussainan 2022년 6월 8일
댓글: Suaad Al-Hussainan 2022년 6월 8일
% 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
Suaad Al-Hussainan 2022년 6월 8일
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