필터 지우기
필터 지우기

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

조회 수: 7 (최근 30일)
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)

답변 (1개)

Krishna
Krishna 2024년 7월 9일 11:15

카테고리

Help CenterFile Exchange에서 Sequence and Numeric Feature Data Workflows에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by