0
votes

I don't know if I'm wrong or if it makes sense but, my idea is to use a single prediction and based on that one, predict the future values (I'm using a LSTM model on Keras). What I'm trying to do is:

1) Get the first X known values (initial_values)

2) Predict using initial_values and get (initial_prediction).

3) Delete the first element of initial_values and append initial_prediction

4) Repeat from step 2) X times.

My code look like this:

predictions = []
y_test_concat = []
num_steps_before = 30

# Step 1

# X_test_scaled_shape: (192, 1)
y_test_concat.append(X_test_scaled[:num_steps_before,:]) 
y_test_concat = np.array(y_test_concat)
y_test_concat.reshape(y_test_concat.shape[0],y_test_concat.shape[1],1)

# Step 2

simulated_predictions.append(model.predict(y_test_concat))

# Step 3 (where I get stucked)

num_steps_to_predict = 10
for i in range(1,num_steps_to_predict):
  ...

So during the next iterations the array should like this:

[initial_value2,initial_value3,...initial_value30, initial_prediction]
[initial_value3,initial_value4,...initial_prediction, initial_prediction2]
...
[initial_value20,initial_value21,...initial_predictionX, initial_predictionY]

Any ideas? I was wondering if there's something already implemented in Keras to do such thing using LSTM.

1
Can you explain your problem in more detail? In most cases, your input to an LSTM will be a time series and it will keep its own hidden state over that time series. It does seem a little strange that you are using a model's own prediction as its input.Luke DeLuccia
The idea is based on one prediction, with some initial values, predict the future X next values. What I always see are predictions but using already known data. So you use [x0...x20] and you get [p1] then you use [x1...x21] and get [p2], my idea is use the predicted value (p1) as an input for my input array, so it would be something like [x1...p1] and the next one... [x2...p1, p2] so I'm adding the predictions as part of the next inputs. Does it make sense? Am I missing something with LSTM?lucaswerner

1 Answers

0
votes

Thanks to @lukedeluccia for his answer, I came up with the solution:

num_steps_before = 30
initial_values = np.array([X_test_scaled[:num_steps_before,:]])
predictions = initial_values

for i in range(0,num_steps_before):
  prediction = model.predict(predictions)
  predictions = np.append(predictions,[prediction])
  predictions = np.delete(predictions,0)
  predictions = predictions.reshape((1,predictions.shape[0],1))