error using trainNetwork Invalid training data. Responses must be a matrix of numeric responses, or a N-by-1 cell array of sequences, where N is the number of sequences
3 views (last 30 days)
Show older comments
Hi
I have this following code and the data set is traffic flow that gathered every 15 seconds and I want to predict data flow but i faced an error "Invalid training data. Responses must be a matrix of numeric responses, or a N-by-1 cell array of sequences, where N is the number of sequences. The feature dimension of all sequences must be the same"and I can't fix it can anyone help me with it
My code is :
clc
close all
clear all
warning off
[~,~,flow_data] = xlsread('two_days.xlsx'); % Here we have two days data
data_mat = cell2mat(flow_data(2:end,3:4));
YTrain = data_mat(:,:)';
XTrain = data_mat(:,:)';
%
% %
XTrain = num2cell(XTrain,1)';
YTrain = num2cell(YTrain,1)';
numResponses = 1 ;
% numResponses = size(YTrain{1},1);
featureDimension = size(XTrain{1},1);
numHiddenUnits = 100;
layers = [ ...
sequenceInputLayer(featureDimension)
lstmLayer(numHiddenUnits)
% dropoutLayer(0.1) %%0.5
fullyConnectedLayer(numResponses)
regressionLayer];
maxepochs = 500;
miniBatchSize = 1;
options = trainingOptions('adam', ... %%adam
'MaxEpochs',maxepochs, ...
'GradientThreshold',1, ...
'InitialLearnRate',0.005, ...
'LearnRateSchedule','piecewise', ...
'LearnRateDropPeriod',125, ...
'LearnRateDropFactor',0.2, ...
'Verbose',1, ...
'Plots','training-progress');
%%Train the Network
net = trainNetwork(XTrain,YTrain,layers,options);
% YTest = data_mat(0.85*length(data_mat):end,1)';
% XTest = data_mat(0.85*length(data_mat):end,1)';
%
% XTest = num2cell(XTest,1);
% YTest = num2cell(YTest,1);
%
% net = resetState(net);
% YPred = predict(net,XTest)
%
%
% y1 = (cell2mat(YPred(1:end, 1:end))); %have to transpose as plot plots columns
% plot(y1)
% hold on
% y2 = (cell2mat(YTest(1:end, 1:end))');
% plot(y2)
0 Comments
Answers (1)
Krishna
on 9 Jul 2024
Hi Arash,
Please review this MATLAB answer it would help this case as well,
Hope this helps.
0 Comments
See Also
Categories
Find more on Image Data Workflows in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!