Multivariate, Multi-step LSTM time series forecast

I'm trying to predict the Pollution using a Multivariate and Multi-step LSTM code, I've been following this tutorial.

I've been following the code until the end, but couldn't understand where the code writer determined the Pollution column to be the code output (predicting the Pollution column instead of an other column?) I'm new to python, and it got me confused.

At first, I thought that this is the part of the code where we define it, but I was wrong:

# invert scaling for forecast
pred_scaler = MinMaxScaler(feature_range=(0, 1)).fit(dataset.values[:,0].reshape(-1, 1))
inv_yhat = pred_scaler.inverse_transform(yhat)
print(inv_yhat.shape)
# invert scaling for actual
inv_y = pred_scaler.inverse_transform(test_y)
print(inv_y.shape)

Any explanations on how he determined the pollution column out of the 7 other columns to be the output?

• Please introduce your problem more clearly, explain what is your goal, what data are you working with, what you tried and what you got so far. At the moment it's not easy to help you. Jun 13 '20 at 16:00
• I'm sorry, My mistake I though I've added the link. Thank you for the remark @Leevo Jun 15 '20 at 15:20

I know this tutorial, it's a good start for RNNs but it contains a lot of passages and transformations that could have been kept shorter.

First, he defines a function called series_to_supervised() to process data to be fed into an RNN. Paragraph 3, line 37:

reframed = series_to_supervised(scaled, 1, 1)

This reframed dataframe contains all data, either y columns and all the X variables to make a prediction.

In the following code block it is turned into a numpy array at line 2:

values = reframed.values

Ok, so now all our information is store in values. Now it's time to separate it in train and test:

train = values[:n_train_hours, :]
test = values[n_train_hours:, :]

And again, each train and test is separated in x and y pieces:

# split into input and outputs
train_X, train_y = train[:, :-1], train[:, -1]
test_X, test_y = test[:, :-1], test[:, -1]

Line 7-8. This is where the dependent variable is separated from the rest. Knowing it was the last column, it was extracted with index -1 (i.e. the last element).

As I said, this tutorial is a good start to learn time series prediction with RNNs. However, I find that sometimes he tried to simplify the steps so much... that he ended up with some messy parts. All those objects: reframed, values, train, test, ... there was no need to make so many of them.

That apart, I'm a fan of the blog. It provided a lot of useful tips on RNNs.

• If you are interested, I pushed a tutorial Notebook on the same task, but with things implemented in a different way, with my own code. Hope that helps. Jun 15 '20 at 17:10
• thank you, great tutorials and link you have given here. I can't understand why you only have only one thumb up here. Anyway, if you have time, would you please also make one LSTM Multivariate Many to Many tutorial ? And particularly, please include differencing, scaling, then reverting them to the tutorial. Because, i have been searching for so long and still can't find one. And then i have tried so hard to figure it out myself, but fail again. Please do let me know when you have one. I appreciate it. Jan 23 '21 at 20:25
• i just followed you in githhub Jan 23 '21 at 20:30