Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Notebook 10: Section 350 function for making future preds #587

Open
talha-0 opened this issue Sep 20, 2023 · 0 comments
Open

Notebook 10: Section 350 function for making future preds #587

talha-0 opened this issue Sep 20, 2023 · 0 comments

Comments

@talha-0
Copy link

talha-0 commented Sep 20, 2023

We are not preparing the data correctly as the latest price must be at the 0th index of the list. Model's forecast are also effected by this we can see the forecast was very high from the last price this was because the 0th index has a higher value than the actual price
Here are my observations:
X_all[-2:]
Output:

array([[47885.62525472, 50032.69313676, 49764.1320816 , 52147.82118698,
        56573.5554719 , 55715.54665129, 58102.19142623],
       [45604.61575361, 47885.62525472, 50032.69313676, 49764.1320816 ,
        52147.82118698, 56573.5554719 , 55715.54665129]])

See how the new price 45604.61575361 moved to the 0th index

SOLUTION:

new = y_all[-WINDOW_SIZE:]
new[::-1]
array([43144.47129086, 45604.61575361, 47885.62525472, 50032.69313676,
       49764.1320816 , 52147.82118698, 56573.5554719 ])

This will correct the order of windows
New function:

def make_future_forecasts(
    values,
    model,
    into_future,
    window_size=WINDOW_SIZE
) -> list:
  """
  Make future forecasts into_future steps after value ends.

  Returns future forecasts as a list of floats.
  """
  # Empty list of future forecast
  future_forecast = []
  # Get the last window of prices to feed to the model
  last_window = values[-window_size:]
  last_window = last_window[::-1]

  # Make into_future number of preds altering the data which model will use for next pred
  for _ in range(into_future):
    # Predict on last window and append the pred in forecast and also in last window(model will predict on its own pred)
    future_pred = model.predict(tf.expand_dims(last_window,axis=0))
    print(f'Predicting on:\n {last_window}-> Prediction: {tf.squeeze(future_pred).numpy()}')
    future_forecast.append(tf.squeeze(future_pred).numpy())
    # Update last window
    last_window=np.append(future_pred,last_window)[:window_size]

  # Return list of forecast
  return future_forecast
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant