Closed nknauer closed 4 years ago
OK I believe I know what's happening here. Thanks for the really detailed analysis and plots.
The issue is the terrible weekly seasonality prediction as you noted. You'll be able to see this if you look at the components plot:
prophet_plot_components(mod.3, forecast_addReg)
there are the two really negative values, for Sat and Sun.
What's happening here is that the stock time series only has data for M-F. This means that the weekly seasonality for Sat and Sun is completely unconstrained, and sometimes can fit very badly. There's some discussion of this in https://facebook.github.io/prophet/docs/non-daily_data.html#data-with-regular-gaps. You don't see this in the model fit to the history, because there the model is only being evaluated at points that have data, which means it is only being evaluated on M-F dates. future.3
, on the other hand, contains every day, including Sat and Sun and so you see the really bad predictions for those dates.
The easiest fix, as described in the documentation link above, is to just not make predictions for Sat and Sun (just drop those dates from future
). The model will work just fine for M-F, and so if you only ask for predictions on M-F everything will be correct.
The alternative would be to turn off weekly seasonality and replace it with 5 binary extra regressors that fit an effect for each of the days that you have data for, like is_Monday
, is_Tuesday
, etc. Then you wouldn't have this issue of the model fitting an effect for Sat and Sun where there isn't any data. I don't think there's any reason to prefer one approach over the other, and the first approach is probably less work..
that did the trick, thank you! This can be closed now. Appreciate the help.
I posted this question in stackoverflow as well and can't figure out why this is happening. https://stackoverflow.com/questions/62971261/r-prophet-time-series-prediction-with-regressors-has-outlier-results
Basically I am trying to predict the future stock price of the ticker:
R
.When I try this with the normal prophet function without regressors, it gives me a reasonable prediction. However when I add in a regressor, the output has 2 low predictions which I don't understand why it's happening. The output is saying weekly seasonality is causing this but my predictions for the future dataframe of the regressor only does not fluctuate which is making this output confusing. Below is my code. Any help would be great, thanks.
When I predict the next 14 days of this stock I get the following:
Now using the sentiment data, I want to add that extra granularity to improve the model. I have daily sentiment data and the data was fluctuating too much so I took a 7-day moving average like below:
You can find the data in my github below:
Now to include this in my model, I would go about it this way:
Plot of sentiment only prediction below with 7-day moving average:
Now when I include this with the stock data, the predictions fluctuate a ton.
Has anyone had this issue before using the prophet package with additional regressors? If you're interested this is the output of the model. The weekly seasonality is the big reason I think this happening but I'm confused that the numbers would fluctuate so much in a prediction when the underlying data is pretty stable.