The prediction sequences are of feature dimension 1 but the input layer expects sequences of feature dimension 2.
11 ビュー (過去 30 日間)
古いコメントを表示
Hello everyone
I try to predict traffic flow by using real time data and previous data. So I have 2 input and one output. I use LSTM for this purpose and then when I want to predict data I use " YPred = predict(net,YTest); " but i face an error The prediction sequences are of feature dimension 1 but the input layer expects sequences of feature dimension 2.
My XTrain has 470 column that has [{2×1 double} ] and YTrain has 479 column with 1*1 double .
and XTest and YTest have 60 columns and the cell is the same as train
I try everything but I can't fix it
please help me
Thanks
My code is :
clc
close all
clear all
warning off
% [~,~,flow_data] = xlsread('two_days.xlsx');
flow_data = xlsread('two_days.xlsx') ; % Here we have two days data
% data_mat = cell2mat(flow_data(2:end,3:4));
data_mat =(flow_data(2:end,3:4));
% XTrain = data_mat(:,3:4)';
% YTrain = data_mat(:,3:4)';
XTrain = data_mat(:,:)';
YTrain = data_mat(:,1)';
XTrain = num2cell(XTrain,1);
YTrain = num2cell(YTrain,1);
% %
numResponses = 1 ;
% numResponses = size(YTrain{1},1);
featureDimension = 2;
numHiddenUnits = 200;
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',225, ...
'LearnRateDropFactor',0.2, ...
'Verbose',1, ...
'Plots','training-progress');
% %%Train the Network
net = trainNetwork(XTrain,YTrain,layers,options);
%
test_data = xlsread('test_data2.xlsx') ; % Here we have two days data
data_mat2 =(test_data(1:end,3:4));
% XTest = data_mat2(:,:)';
YTest = data_mat2(:,1)';
XTest = data_mat2(:,1)';
XTrain = num2cell(XTest,1);
YTrain = num2cell(YTest,1);
net = resetState(net);
YPred = predict(net,YTest);
YPred = round(YPred)
% net = predictAndUpdateState(net,XTrain);
% [net,YPred] = predictAndUpdateState(net,YTrain(end));
% %
% % %
% % Predict as long as the test period
% numTimeStepsTest = numel(YTest);
% for i = 2:numTimeStepsTest
% [net,YPred(:,i)] = predictAndUpdateState(net,YPred(:,i-1),'ExecutionEnvironment','cpu');
% end
% YPred
% 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 件のコメント
回答 (0 件)
参考
カテゴリ
Help Center および File 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!