Trying to create neural network but getting a NaN error from dataset

1 Ansicht (letzte 30 Tage)
%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 Kommentare
KSSV
KSSV am 2 Dez. 2021
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?
KSSV
KSSV am 2 Dez. 2021
How is your data? Attach a snippet of data.

Melden Sie sich an, um zu kommentieren.

Akzeptierte Antwort

Walter Roberson
Walter Roberson am 2 Dez. 2021
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.

Weitere Antworten (2)

Nathaniel Porter
Nathaniel Porter am 2 Dez. 2021
%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);

yanqi liu
yanqi liu am 2 Dez. 2021
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);

Kategorien

Mehr zu Deep Learning Toolbox finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by