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

3 ビュー (過去 30 日間)
Nathaniel Porter
Nathaniel Porter 2021 年 12 月 1 日
コメント済み: Nathaniel Porter 2021 年 12 月 2 日
%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
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?
KSSV
KSSV 2021 年 12 月 2 日
How is your data? Attach a snippet of data.

サインインしてコメントする。

採用された回答

Walter Roberson
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 件)

Nathaniel Porter
Nathaniel Porter 2021 年 12 月 2 日
%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 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 ExchangeDeep Learning for Image Processing についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by