How to predict multiple time series data using deep learning

조회 수: 48 (최근 30일)
Athira t
Athira t 2019년 8월 24일
댓글: Sharan Magavi 2020년 1월 16일
My dataset (18000 * 7 ) consists of air quality parameters. The parameters are PM10 concentration, wind speed, wind direction,temp, pressure, humidity, solar radiation. I want to predict the future pm10 concentration. I tried with the code available, but i cannot use it. please help me with the code
data=xlsread('pollutant.xlsx')
data=data';
dataTrainStandardized = (dataTrain - mu) / sig;
XTrain = dataTrainStandardized(1:end-1);
YTrain = dataTrainStandardized(2:end);
numFeatures = 6;
numResponses = 1;
numHiddenUnits = 200;
numTimeStepsTrain = floor(0.8*numel(data));
dataTrain = data(1:numTimeStepsTrain+1);
dataTest = data(numTimeStepsTrain+1:end);
mu = mean(dataTrain);
sig = std(dataTrain);
layers = [ ...
sequenceInputLayer(numFeatures)
lstmLayer(numHiddenUnits)
fullyConnectedLayer(numResponses)
regressionLayer];
options = trainingOptions('adam', ...
'MaxEpochs',250, ...
'GradientThreshold',1, ...
'InitialLearnRate',0.005, ...
'LearnRateSchedule','piecewise', ...
'LearnRateDropPeriod',125, ...
'LearnRateDropFactor',0.2, ...
'Verbose',0, ...
'Plots','training-progress');
dataTestStandardized = (dataTest - mu) / sig;
XTest = dataTestStandardized(1:end-1);
net = predictAndUpdateState(net,XTrain);
[net,YPred] = predictAndUpdateState(net,YTrain(end));
numTimeStepsTest = numel(XTest);
for i = 2:numTimeStepsTest
[net,YPred(:,i)] = predictAndUpdateState(net,YPred(:,i-1),'ExecutionEnvironment','cpu');
end
YPred = sig*YPred + mu;
YTest = dataTest(2:end);
rmse = sqrt(mean((YPred-YTest).^2))
figure
plot(dataTrain(1:end-1))
hold on
idx = numTimeStepsTrain:(numTimeStepsTrain+numTimeStepsTest);
plot(idx,[data(numTimeStepsTrain) YPred],'.-')
hold off
xlabel("Hour")
ylabel("Pm10 hourly concentration")
title("Forecast")
legend(["Observed" "Forecast"])

답변 (1개)

Raunak Gupta
Raunak Gupta 2019년 8월 27일
Hi,
In my understanding you trying to use Regression based LSTM to predict the PM10 concentration as mentioned in the question. I assume that the PM10 concentration parameter resides in the last column of dataset file. I see you have used example from here. Here the number of features is only 1 that’s why you are facing problem.
The number of parameters you want to train on are 6, So I suggest changing YTrain in the code to have only the last column of the data. Also, the dataset split must be done to get all six parameters in the test and train data. Instead of using numel, try array indexing for getting appropriate number of samples for training and testing.
numTimeStepsTrain = floor(0.8*size(data,1));
dataTrain = data(1:numTimeStepsTrain+1,:);
dataTest = data(numTimeStepsTrain+1:end,:);
% DataSet Size --> (18000,7)
XTrain = dataTrainStandardized(:,1:6);
YTrain = dataTrainStandardized(:,7);
XTest = dataTestStandardized(:,1:6);
YTest = dataTestStandardized(:,7);
For multiple feature regression you can refer to the Sequence to Sequence Regression.
You can try out different other fine-tuning steps for getting much better results by looking into the following resources.
  댓글 수: 3
Raunak Gupta
Raunak Gupta 2019년 8월 28일
Hi,
You can look into the Sequence to Sequence Regression mentioned in the above answer as It contains end to end workflow of training the kind of Network you want. Also If you want to predict the future PM10 Concentration with previous PM10 concentration only then you can go ahead with the code you posted first with only the last column of the data matrix.
Sharan Magavi
Sharan Magavi 2020년 1월 16일
as per my understanding you dont need to calculate mu and sig for all the variable ( XTrain, Test, etc)
you need to calculate it only on the Training dataset and APPLY the same mu and sig to the test set to normalise it.

댓글을 달려면 로그인하십시오.

카테고리

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

제품


릴리스

R2019a

Community Treasure Hunt

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

Start Hunting!

Translated by