Trying to create neural network but getting a NaN error from dataset
2 次查看(过去 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!