tensorflow-deep-learning
tensorflow-deep-learning copied to clipboard
Notebook 10: Section 350 function for making future preds
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