Invalid training data. For classification tasks, responses must be a vector of categorical responses. For regression tasks, responses must be a vector, a matrix, or a 4-D arra
14 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Nathaniel Porter
el 4 de Mzo. de 2022
Comentada: Nathaniel Porter
el 7 de Mzo. de 2022
clc; clear all; close all;
load Projectdata.mat
% Split Data Glucose
GlucoseReadings_T = GlucoseReadings';
GlucoseReadings_train = GlucoseReadings_T;
train_GlucoseReadings = GlucoseReadings_train(1:84,:);
train_GR_output = GR_output(1:17);
%Split Data Insulin
InsulinReadings_T = InsulinReadings';
InsulinReadings_train = InsulinReadings_T;
train_InsulinReadings = InsulinReadings_train(1:84,:);
train_INS_output = INS_output(1:17);
% Data Batch Glucose
GlucoseReadingsTrain=(reshape(train_GlucoseReadings', [1749,84]));
val_GlucoseReadings = GlucoseReadings_train(85:102,:);
val_GR_output = GR_output(85:102);
GlucoseReadingsVal=(reshape(val_GlucoseReadings', [1749,18]));
test_GlucoseReadings =GlucoseReadings_train(103:120,:);
test_GR_output = GR_output(103:120);
GlucoseReadingsTest=(reshape(test_GlucoseReadings', [1749,18]));
numFeatures = size(GlucoseReadings_T,2);
%Data Batch Insulin
InsulinReadingsTrain=(reshape(train_InsulinReadings', [1758,84]));
val_InsulinReadings = InsulinReadings_train(85:102,:);
val_INS_output = INS_output(85:102);
InsulinReadingsVal=(reshape(val_InsulinReadings', [1758,18]));
test_InsulinReadings = InsulinReadings_train(103:120,:);
test_INS_output = INS_output(103:120);
InsulinReadingsTest=(reshape(test_InsulinReadings', [1758,18]));
numFeatures1 = size(InsulinReadings_T,2);
% number of hidden units represent the size of the data
numHiddenUnits = 120;
%number of classes represent different patients normal,LIS,type2....
numClasses = length(categories(categorical(GR_output)));
numClasses1 = length(categories(categorical(INS_output)));
layers = [ ...
sequenceInputLayer(numFeatures)
%dropoutLayer(0.5)
instanceNormalizationLayer
bilstmLayer(round(numHiddenUnits/2),'OutputMode','sequence')
fullyConnectedLayer(numClasses)
instanceNormalizationLayer
softmaxLayer
classificationLayer];
options = trainingOptions('adam', ...
'MaxEpochs',100, ...
'GradientThreshold',1, ...
'Verbose',false, ...
'ValidationData',{GlucoseReadingsVal, val_GR_output},...
'ValidationData',{InsulinReadingsVal, val_INS_output},...
'LearnRateDropFactor',0.2,...
'LearnRateDropPeriod',5,...
'Plots','training-progress');
% Train
whos
net = trainNetwork(GlucoseReadingsTrain,train_GR_output,layers,options);
net1 = trainNetwork(InsulinReadingsTrain,train_INS_output,layers,options);
% Test
miniBatchSize = 27;
GR_outputPred = classify(net,GlucoseReadingsTest,...
'MiniBatchSize',miniBatchSize,...
'Environment','cpu');
acc = mean(GR_outputPred(:) == categorical(test_GR_output(:)))
acc1 = mean(INS_outputPred(:) == categorical(test_INS_output(:)))
figure
t = confusionchart(categorical(test_GR_output(:)),GR_outputPred(:));
figure
t1 = confusionchart(categorical(test_INS_output(:)),INS_outputPred(:));
2 comentarios
KSSV
el 4 de Mzo. de 2022
Please note that, you have to close/ acknowledge the already posted question and go for other question.
Respuesta aceptada
Walter Roberson
el 4 de Mzo. de 2022
net = trainNetwork(GlucoseReadingsTrain, categorical(train_GR_output), layers,options);
2 comentarios
Walter Roberson
el 4 de Mzo. de 2022
train_GR_output = GR_output(1:17);
That response should only be used with an input of size 17.
You should not be training on data only from one class: you should be training on data from all of your classes.
Más respuestas (1)
yanqi liu
el 7 de Mzo. de 2022
clc; clear all; close all;
load Projectdata.mat
% Split Data Glucose
GR_output=categorical(GR_output);
INS_output=categorical(INS_output);
GlucoseReadings_T = GlucoseReadings';
GlucoseReadings_train = GlucoseReadings_T;
train_GlucoseReadings = GlucoseReadings_train(1:84,:);
train_GR_output = GR_output(1:84);
%Split Data Insulin
InsulinReadings_T = InsulinReadings';
InsulinReadings_train = InsulinReadings_T;
train_InsulinReadings = InsulinReadings_train(1:84,:);
train_INS_output = INS_output(1:84);
% Data Batch Glucose
GlucoseReadingsTrain=(reshape(train_GlucoseReadings', [1749,84]));
val_GlucoseReadings = GlucoseReadings_train(85:102,:);
val_GR_output = GR_output(85:102);
GlucoseReadingsVal=(reshape(val_GlucoseReadings', [1749,18]));
test_GlucoseReadings =GlucoseReadings_train(103:120,:);
test_GR_output = GR_output(103:120);
GlucoseReadingsTest=(reshape(test_GlucoseReadings', [1749,18]));
numFeatures = size(GlucoseReadings_T,2);
%Data Batch Insulin
InsulinReadingsTrain=(reshape(train_InsulinReadings', [1758,84]));
val_InsulinReadings = InsulinReadings_train(85:102,:);
val_INS_output = INS_output(85:102);
InsulinReadingsVal=(reshape(val_InsulinReadings', [1758,18]));
test_InsulinReadings = InsulinReadings_train(103:120,:);
test_INS_output = INS_output(103:120);
InsulinReadingsTest=(reshape(test_InsulinReadings', [1758,18]));
numFeatures1 = size(InsulinReadings_T,2);
% number of hidden units represent the size of the data
numHiddenUnits = 120;
%number of classes represent different patients normal,LIS,type2....
numClasses = length(categories(categorical(GR_output)));
numClasses1 = length(categories(categorical(INS_output)));
layers = [ ...
sequenceInputLayer(numFeatures)
dropoutLayer(0.5)
%instanceNormalizationLayer
bilstmLayer(round(numHiddenUnits/2),'OutputMode','sequence')
fullyConnectedLayer(numClasses)
%instanceNormalizationLayer
dropoutLayer(0.5)
softmaxLayer
classificationLayer];
layers1 = [ ...
sequenceInputLayer(numFeatures1)
dropoutLayer(0.5)
%instanceNormalizationLayer
bilstmLayer(round(numHiddenUnits/2),'OutputMode','sequence')
fullyConnectedLayer(numClasses)
%instanceNormalizationLayer
dropoutLayer(0.5)
softmaxLayer
classificationLayer];
options = trainingOptions('adam', ...
'MaxEpochs',100, ...
'GradientThreshold',1, ...
'Verbose',false, ...
'ValidationData',{GlucoseReadingsVal, val_GR_output},...
'LearnRateDropFactor',0.2,...
'LearnRateDropPeriod',5,...
'Plots','training-progress');
options1 = trainingOptions('adam', ...
'MaxEpochs',100, ...
'GradientThreshold',1, ...
'Verbose',false, ...
'ValidationData',{InsulinReadingsVal, val_INS_output},...
'LearnRateDropFactor',0.2,...
'LearnRateDropPeriod',5,...
'Plots','training-progress');
% Train
% whos
net = trainNetwork(GlucoseReadingsTrain,train_GR_output,layers,options);
net1 = trainNetwork(InsulinReadingsTrain,train_INS_output,layers1,options1);
% Test
miniBatchSize = 27;
GR_outputPred = classify(net,GlucoseReadingsTest,...
'MiniBatchSize',miniBatchSize,...
'ExecutionEnvironment','cpu');
acc = mean(GR_outputPred(:) == categorical(test_GR_output(:)))
INS_outputPred = classify(net1,InsulinReadingsTest,...
'MiniBatchSize',miniBatchSize,...
'ExecutionEnvironment','cpu');
acc1 = mean(INS_outputPred(:) == categorical(test_INS_output(:)))
figure
t = confusionchart(categorical(test_GR_output(:)),GR_outputPred(:));
figure
t1 = confusionchart(categorical(test_INS_output(:)),INS_outputPred(:));
Ver también
Categorías
Más información sobre Sequence and Numeric Feature Data Workflows en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!