1

Is my first approach to LSTM. I m trying to predict a Forecast in a time series. I m following this Github example

And all work for me in the same way.

I slip in train and test, I plot the loss and plot a difference for actual and predicted.

But if I want to predict the next month's values? Is possible with LSTM?

I obtained this graph, but isn't very interesting for me, because I wish to try to predict future values, in order to try to understand the trend

enter image description here

This is my split data in train and test set :

# Split into training/test sets
train_size = int(len(data) * 0.8)
train, test = data[:train_size,], data[train_size:,]

# Prepare the data in a format required for LSTM (samples, timesteps, features)

def Create_Dataset(df, lookback=1):
    X, Y = [], []
    for i in range(len(df) - lookback - 1):
        X.append(df[i:(i+lookback), 0])
        Y.append(df[i + lookback,0])
    return np.array(X), np.array(Y)

lookback = 30
X_train, Y_train = Create_Dataset(train, lookback)
X_test, Y_test   = Create_Dataset(test, lookback)

X_train = np.reshape(X_train, (X_train.shape[0], 1, X_train.shape[1]))
X_test  = np.reshape(X_test, (X_test.shape[0], 1, X_test.shape[1]))
theantomc
  • 619
  • 2
  • 7
  • 32
  • use `model.predict(X)` with `X` as your desired date or whatever your data looks like – luigigi Mar 03 '20 at 08:08
  • Yes, it's possible. This example has lagged predictions: https://machinelearningmastery.com/multivariate-time-series-forecasting-lstms-keras/ – Itamar Mushkin Mar 03 '20 at 08:19
  • @ItamarMushkin this example is quite similar to mine. In fact, he said " we will only fit the model on the first year of data, then evaluate it on the remaining 4 years of data. If you have time, consider exploring the inverted version of this test harness." . i wish predict new data (not data from train and test that i already know) – theantomc Mar 03 '20 at 09:11
  • In my example I have train_predict = model.predict(X_train) test_predict = model.predict(X_test) @luigigi – theantomc Mar 03 '20 at 09:12
  • This is no different than predicting on test data – Itamar Mushkin Mar 03 '20 at 09:15
  • Yes but i don't have future data. Ad example, if my dataset have values until 3/03/2020, the LSTM produce a values for next 7 days until 10/03. The model should "invent" new data, based on previous one @ItamarMushkin – theantomc Mar 03 '20 at 09:20
  • Does this answer your question? [How to train a RNN with LSTM cells for time series prediction](https://stackoverflow.com/questions/35961216/how-to-train-a-rnn-with-lstm-cells-for-time-series-prediction) – Itamar Mushkin Mar 03 '20 at 10:56
  • Yes, if you train the model to predict n steps forward, this is what it'll be able to do. See here: https://stackoverflow.com/questions/35961216/how-to-train-a-rnn-with-lstm-cells-for-time-series-prediction?rq=1 – Itamar Mushkin Mar 03 '20 at 10:56
  • @ItamarMushkin can you give me an example? i edit my question adding the code of splitting train and test set – theantomc Mar 03 '20 at 11:12

0 Answers0