Hvass-Labs / TensorFlow-Tutorials

TensorFlow Tutorials with YouTube Videos

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Now how to forecast the future without knowing the known values?

windowshopr opened this issue · comments

I looked back at some of the closed comments but didn't see an answer, and would love your input (and maybe some other newbies would too), as I don't want to butcher your amazing work with some half-assed workaround, and figured it would be faster than on StackOverflow as you'd know the project best. Even if you have a resource for me to check out regarding this that would be fine, just seems like a lot of how-to's overlook this step.

I'm simply wanting to now get a forecast using the most recent part of the dataset. For example, I trained a model using 56 days (timesteps) previous to predict 1 day in the future using stock price data, using your workbook. It plots the real and predicted accuracy's from the validation dataset like it should, but now what I want to do is use the .predict() function and feed it the bottom 56 rows of my original dataset to get it's 1 day future prediction, but I'm stuck and I know I'm not doing it right. There's too many different versions of TF prediction workbooks out there.

So far as a pseudo-code I have:

# Now predict tomorrow!
# First, reshift target column down one to reset the dataset
df['Close'] = df['Close'].shift(shift_steps) 

start_idx = len(df['Close']) - sequence_length  # sequence_length is 56
end_idx = len(df['Close'])

x_new = df.iloc[start_idx : end_idx, :] # 56 rows x 37 columns
# We now have selected the last 56 rows of the dataset and all 37 columns

result = model.predict(x=np.expand_dims(x_new, axis=0))
print('Raw result is :', result) 

Out: Raw result is : -0.1898764      # ?????????

# Try inverse transforming??
result = y_scaler.inverse_transform(result[0])
print('Inversed Result is :', result) 

Out: Inversed Result is : -13.540215      # ?????????

When the next day's closing price should be somewhere between 24-25, and certainly not negative.

How would you go about running a prediction with your time series forecasting workbook? Thanks!

Thanks for the compliment.

That tutorial was made almost 20 months ago so I can't remember the details. In general I also don't give support when people modify the tutorials or use their own datasets, because I could spend the rest of my life doing that.

If you find a solution then please post it in this thread, so it might help others in the future.

And that’s totally fair, I will work on it and post it here when I’ve learned how to do it. Don’t want to add any undo work on your end.

I’m hoping to incorporate the same plot function so that it’ll show all the known values and then the next day’s future prediction, so the pred line will extend one (or more) timesteps into the future.

Thanks for your work! It helped me a lot.