Trying to create neural network but getting a NaN error from dataset
조회 수: 3 (최근 30일)
이전 댓글 표시
%Import/Upload data
load generated_data.mat
%transposing glucose data
X1_T = X1';
%transposing insulin data
X2_T = X2';
%Separating data in training, validation and testing data
X1_train = X1_T;
%Partioning data for training
train_X1 = X1_train(1:120,:);
%Separating and partioning for validation data
val_X1 = X1_train(121:150,:);
%Separating and partioning for test data
test_X1 = X1_train(151:180,:);
%Separating data in training, validation and testing data
X2_train = X2_T;
%Partioning data for training
train_X2 = X2_train(1:120,:);
%Separating and partioning for validation data
val_X2 = X2_train(121:150,:);
%Separating and partioning for test data
test_X2 = X2_train(151:180,:);
%The number of features chosen to be two representing both glucose and
%insulin
numFeatures = 2;
% number of hidden units represent the size of the data
numHiddenUnits = 180;
%number of classes represent different patients normal,LIS,type2....
numClasses = 6;
layers = [ ...
sequenceInputLayer(numFeatures)
lstmLayer(numHiddenUnits,'OutputMode','last')
fullyConnectedLayer(numClasses)
softmaxLayer
classificationLayer];
options = trainingOptions('adam', ...
'MaxEpochs',60, ...
'GradientThreshold',2, ...
'Verbose',0, ...
'Plots','training-progress');
isnan(train_X1)
net = trainNetwork(train_X1,Y1,layers,options);
댓글 수: 3
KSSV
2021년 12월 2일
OP commented:
So it is a large set of data can you recommend any ways that I can alter the data to get rid of these Nans?
채택된 답변
Walter Roberson
2021년 12월 2일
net = trainNetwork(train_X1, string(Y1), layers, options);
However:
Error using trainNetwork (line 184)
The training sequences are of feature dimension 120 but the input layer expects sequences of feature dimension 2.
And indeed you coded
numFeatures = 2;
If you are only wanting to pass in two features then you are going to have to extract those two features out of your 120 x 2289 array.
추가 답변 (2개)
yanqi liu
2021년 12월 2일
clc; clear all; close all;
%Import/Upload data
load generated_data.mat
%transposing glucose data
X1_T = X1';
%transposing insulin data
X2_T = X2';
%Separating data in training, validation and testing data
X1_train = X1_T;
%Partioning data for training
train_X1 = X1_train(1:120,:);
train_Y1 = Y1(1:120);
%Separating and partioning for validation data
val_X1 = X1_train(121:150,:);
%Separating and partioning for test data
test_X1 = X1_train(151:180,:);
%Separating data in training, validation and testing data
X2_train = X2_T;
%Partioning data for training
train_X2 = X2_train(1:120,:);
%Separating and partioning for validation data
val_X2 = X2_train(121:150,:);
%Separating and partioning for test data
test_X2 = X2_train(151:180,:);
%The number of features chosen to be two representing both glucose and
%insulin
numFeatures = size(X1_T,2);
% number of hidden units represent the size of the data
numHiddenUnits = 180;
%number of classes represent different patients normal,LIS,type2....
numClasses = length(categories(categorical(Y1)));
layers = [ ...
sequenceInputLayer(numFeatures)
lstmLayer(numHiddenUnits)
fullyConnectedLayer(numClasses)
softmaxLayer
classificationLayer];
options = trainingOptions('adam', ...
'MaxEpochs',60, ...
'GradientThreshold',2, ...
'Verbose',0, ...
'Plots','training-progress');
net = trainNetwork(X1_train',categorical(Y1),layers,options);
참고 항목
카테고리
Help Center 및 File Exchange에서 Deep Learning for Image Processing에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!