Number of observations in X and Y disagree. For convolution neural network

1 回表示 (過去 30 日間)
Nathaniel Porter
Nathaniel Porter 2021 年 12 月 5 日
コメント済み: yanqi liu 2021 年 12 月 13 日
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);
%DataParts = zeros(size(Train_inputX1,1), size(Train_inputX1,2),1,2); %(4500,400,1,2)
%DataParts(:,:,:,1) = real(cell2mat(Train_inputX1));
%DataParts(:,:,:,2) = imag(cell2mat(Train_inputX1)) ;
XTrain=(reshape(train_X1, [120,1,1,2289])); %Train data
%Separating and partioning for validation data
val_X1 = X1_train(121:150,:);
val_Y1 = Y1(121:150);
XVal=(reshape(val_X1, [30,1,1,2289])); %Train data
%Separating and partioning for test data
test_X1 = X1_train(151:180,:);
test_Y1 = Y1(151:180);
XTest=(reshape(test_X1, [30,1,1,2289])); %Train data
%Xtest=(reshape(test_X1, [120,1,1,2289])); %Train data
%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
%% NETWORK ARCHITECTURE
layers = [imageInputLayer([120 1 1]) % Creating the image layer
convolution2dLayer([102 1],3,'Stride',1)
maxPooling2dLayer(2,'Stride',2,'Padding',[0 0 0 1])
% convolution2dLayer([24 1],10,'Stride',1)
% maxPooling2dLayer(2,'Stride',2,'Padding',[0 0 0 1])
% convolution2dLayer([11 1],10,'Stride',1)
% maxPooling2dLayer(2,'Stride',2,'Padding',[0 0 0 1])
% convolution2dLayer([9 1],10,'Stride',1)
% maxPooling2dLayer(2,'Stride',2,'Padding',[0 0 0 1])
fullyConnectedLayer(6)
%fullyConnectedLayer(6)
%fullyConnectedLayer(6)
softmaxLayer
classificationLayer];
% Specify training options.
opts = trainingOptions('adam', ...
'MaxEpochs',50, ...
'Shuffle','every-epoch', ...
'Plots','training-progress', ...
'Verbose',false, ...
'ValidationData',{XVal,val_Y1},...
'ValidationPatience',Inf);
%% Train network
%net = trainNetwork(XTrain,Trainoutfinal,layers,opts);
net1 = trainNetwork(XTrain,categorical(train_Y1),layers,opts);
%% Compare against testing Data
miniBatchSize =27;
YPred = classify(net1,test_X1, ...
MiniBatchSize=miniBatchSize, ...
SequencePaddingDirection="left");
acc = mean(YPred == categorical(test_Y1));
figure
t = confusionchart(categorical(test_Y1),YPred);
  1 件のコメント
Rik
Rik 2021 年 12 月 8 日
Have a read here and here. It will greatly improve your chances of getting an answer.
Posting duplicates does not help, so please don't.

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

採用された回答

yanqi liu
yanqi liu 2021 年 12 月 9 日
yes,sir,may be upload generated_data.mat to make some analysis
  11 件のコメント
Nathaniel Porter
Nathaniel Porter 2021 年 12 月 13 日
Thank you. I realized you got an acc = 0.900 but when I ran the code I got 0.677 any reasons as to the change?
yanqi liu
yanqi liu 2021 年 12 月 13 日
yes,sir,i think
ind = randperm(size(X1_T, 1));
may be get different train、test、val
so,i think the data split should make prepare,and use the 6 classies data

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeImage Data Workflows についてさらに検索

製品


リリース

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by