How to predict multiple time series data using deep learning
9 views (last 30 days)
Show older comments
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"])
0 Comments
Answers (1)
Raunak Gupta
on 27 Aug 2019
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);
You can try out different other fine-tuning steps for getting much better results by looking into the following resources.
3 Comments
Raunak Gupta
on 28 Aug 2019
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
on 16 Jan 2020
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.
See Also
Categories
Find more on Sequence and Numeric Feature 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!