CLASSIFYING GRAPH DATA TO CATEGORICAL LABEL USING LSTM
Hi I have the following code here, in which I was trying to train an LSTM to classify input data to catergorical lables as see below:
I get the following error
Error using trainnet (line 46)
Number of observations in predictors (1) and targets (897) must match. Check that the data and network are
consistent.
Error in LSTMGomz (line 40)
net = trainnet(XTrain,TTrain,layers,"crossentropy",options);
>>
Please help where did I go wrong
label = strings(997,1);
label(1:200) = ‘graphtype1’;
label(201:399) = ‘graphtype2’;
label(400:598) = ‘graphtype3’;
label(599:798) = ‘graphtype4’;
label(799:997) = ‘graphtype5’;
className = categorical(label);
className2 = categories(className);
Datain = xlsread(‘C:UsersernesOneDriveDocumentsMATLABLSTMdataIn.xlsx’);
% Above Datain has 997 graphs each with 100 samples
% E.g for graphs Datain(1:200,:) – graphtype 1
% graphs Datain(201:399) – graphtype 2 and so on
%So my objective is to train my LSTM using the graphs to labels
numObservations = 997;
[idxTrain,idxTest] = trainingPartitions(numObservations,[0.9 0.1]);
XTrain = Datain(idxTrain,:);% in Xtrain – there are 897 graphs each with 100 values, so
% Xtrain is 897 x 100,
TTrain = className(idxTrain,:);
numHiddenUnits = 120;
numClasses = 5;
layers = [
sequenceInputLayer(100) % I am not sure about this input, because my data comes in 1 by 100 arrys of a seq
%,with 1 – 100 ms timestamps
bilstmLayer(numHiddenUnits,OutputMode="last")
fullyConnectedLayer(numClasses)
softmaxLayer]
options = trainingOptions("adam", …
MaxEpochs=200, …
InitialLearnRate=0.002,…
GradientThreshold=1, …
Shuffle="never", …
Plots="training-progress", …
Metrics="accuracy", …
Verbose=false);
net = trainnet(XTrain,TTrain,layers,"crossentropy",options);Hi I have the following code here, in which I was trying to train an LSTM to classify input data to catergorical lables as see below:
I get the following error
Error using trainnet (line 46)
Number of observations in predictors (1) and targets (897) must match. Check that the data and network are
consistent.
Error in LSTMGomz (line 40)
net = trainnet(XTrain,TTrain,layers,"crossentropy",options);
>>
Please help where did I go wrong
label = strings(997,1);
label(1:200) = ‘graphtype1’;
label(201:399) = ‘graphtype2’;
label(400:598) = ‘graphtype3’;
label(599:798) = ‘graphtype4’;
label(799:997) = ‘graphtype5’;
className = categorical(label);
className2 = categories(className);
Datain = xlsread(‘C:UsersernesOneDriveDocumentsMATLABLSTMdataIn.xlsx’);
% Above Datain has 997 graphs each with 100 samples
% E.g for graphs Datain(1:200,:) – graphtype 1
% graphs Datain(201:399) – graphtype 2 and so on
%So my objective is to train my LSTM using the graphs to labels
numObservations = 997;
[idxTrain,idxTest] = trainingPartitions(numObservations,[0.9 0.1]);
XTrain = Datain(idxTrain,:);% in Xtrain – there are 897 graphs each with 100 values, so
% Xtrain is 897 x 100,
TTrain = className(idxTrain,:);
numHiddenUnits = 120;
numClasses = 5;
layers = [
sequenceInputLayer(100) % I am not sure about this input, because my data comes in 1 by 100 arrys of a seq
%,with 1 – 100 ms timestamps
bilstmLayer(numHiddenUnits,OutputMode="last")
fullyConnectedLayer(numClasses)
softmaxLayer]
options = trainingOptions("adam", …
MaxEpochs=200, …
InitialLearnRate=0.002,…
GradientThreshold=1, …
Shuffle="never", …
Plots="training-progress", …
Metrics="accuracy", …
Verbose=false);
net = trainnet(XTrain,TTrain,layers,"crossentropy",options); Hi I have the following code here, in which I was trying to train an LSTM to classify input data to catergorical lables as see below:
I get the following error
Error using trainnet (line 46)
Number of observations in predictors (1) and targets (897) must match. Check that the data and network are
consistent.
Error in LSTMGomz (line 40)
net = trainnet(XTrain,TTrain,layers,"crossentropy",options);
>>
Please help where did I go wrong
label = strings(997,1);
label(1:200) = ‘graphtype1’;
label(201:399) = ‘graphtype2’;
label(400:598) = ‘graphtype3’;
label(599:798) = ‘graphtype4’;
label(799:997) = ‘graphtype5’;
className = categorical(label);
className2 = categories(className);
Datain = xlsread(‘C:UsersernesOneDriveDocumentsMATLABLSTMdataIn.xlsx’);
% Above Datain has 997 graphs each with 100 samples
% E.g for graphs Datain(1:200,:) – graphtype 1
% graphs Datain(201:399) – graphtype 2 and so on
%So my objective is to train my LSTM using the graphs to labels
numObservations = 997;
[idxTrain,idxTest] = trainingPartitions(numObservations,[0.9 0.1]);
XTrain = Datain(idxTrain,:);% in Xtrain – there are 897 graphs each with 100 values, so
% Xtrain is 897 x 100,
TTrain = className(idxTrain,:);
numHiddenUnits = 120;
numClasses = 5;
layers = [
sequenceInputLayer(100) % I am not sure about this input, because my data comes in 1 by 100 arrys of a seq
%,with 1 – 100 ms timestamps
bilstmLayer(numHiddenUnits,OutputMode="last")
fullyConnectedLayer(numClasses)
softmaxLayer]
options = trainingOptions("adam", …
MaxEpochs=200, …
InitialLearnRate=0.002,…
GradientThreshold=1, …
Shuffle="never", …
Plots="training-progress", …
Metrics="accuracy", …
Verbose=false);
net = trainnet(XTrain,TTrain,layers,"crossentropy",options); lstm sequence to text MATLAB Answers — New Questions