0
$\begingroup$

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?

$\endgroup$
  • 1
    $\begingroup$ 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. $\endgroup$ – Leevo Jun 13 at 16:00
  • $\begingroup$ I'm sorry, My mistake I though I've added the link. Thank you for the remark @Leevo $\endgroup$ – Giselle Jun 15 at 15:20
0
$\begingroup$

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.

| improve this answer | |
$\endgroup$
  • $\begingroup$ 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. $\endgroup$ – Leevo Jun 15 at 17:10

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.