Prophet: Eliminate weekends?

Created on 6 Oct 2017  Â·  10Comments  Â·  Source: facebook/prophet

My input data only consists of data M-F. I also include an external regressor for days of the week (1 = Monday, 2 = Tuesday... 5 = Friday).
So, my input data has the first column as the date (ds), second column as y, and third column as my external regressor. My dates do not include weekends.

However, when I forecast using prophet, it predicts on weekends, which I'm afraid might skew my actual days of the week predictions (which are actually pretty good).

So, is there a way to have prophet not forecast on weekends? Perhaps I can label them as holidays?

Most helpful comment

If I understand correctly, this is related to the issue described for monthly data here: https://facebook.github.io/prophet/docs/non-daily_data.html

The main issue in using Prophet with M-F data is that if you have weekly seasonality turned on, the term for Sat and Sun will be unidentified and so you can get bad behavior if you then try to forecast for Sat and Sun. As described in the docs there, everything is still correct if you just don't make a forecast for Sat and Sun. So remove Saturdays and Sundays from the future dataframe that you pass into predict. Having missing data on the weekends, in either the history or the future, is not an issue for the model.

One thing about external regressors. Are you using these to try and add weekly seasonality? The built-in weekly seasonality is equivalent to having a dummy variable for each day of the week. If you are adding an extra regressor that is a single column with values [1,2,3,4,5], then the extra regressor is included as a column in the linear part of the model and this column would add an effect that is 5x stronger on Friday than on Monday.

All 10 comments

If I understand correctly, this is related to the issue described for monthly data here: https://facebook.github.io/prophet/docs/non-daily_data.html

The main issue in using Prophet with M-F data is that if you have weekly seasonality turned on, the term for Sat and Sun will be unidentified and so you can get bad behavior if you then try to forecast for Sat and Sun. As described in the docs there, everything is still correct if you just don't make a forecast for Sat and Sun. So remove Saturdays and Sundays from the future dataframe that you pass into predict. Having missing data on the weekends, in either the history or the future, is not an issue for the model.

One thing about external regressors. Are you using these to try and add weekly seasonality? The built-in weekly seasonality is equivalent to having a dummy variable for each day of the week. If you are adding an extra regressor that is a single column with values [1,2,3,4,5], then the extra regressor is included as a column in the linear part of the model and this column would add an effect that is 5x stronger on Friday than on Monday.

Ah, yes, my external regressors are a single column with values [1, 2, 3, 4, 5]. Sounds like I should change it to a non-numeric value, such as a string?

Will try with that and see how it works. Thanks for responding!

Not an expert but if you do need those regressors then you probably want to
set a dummy column for M-F and use a 0 or 1 where appropriate. Better
explained here https://www.otexts.org/fpp/5/2.

On Thu, Oct 12, 2017, 6:45 PM Grant Ognibene notifications@github.com
wrote:

Ah, yes, my external regressors are a single column with values [1, 2, 3,
4, 5]. Sounds like I should change it to a non-numeric value, such as a
string?

Will try with that and see how it works. Thanks for responding!

—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
https://github.com/facebook/prophet/issues/323#issuecomment-336311189,
or mute the thread
https://github.com/notifications/unsubscribe-auth/ANCOqvPzPGrUSbqt2dbQi6Vl1ySveP7Mks5srqR7gaJpZM4Pv4bN
.

The link from @ryantsullivan is exactly what it should be, a separate binary column for each day.

This seems to be resolved, but feel free to re-open if there is more to discuss here.

Hi there, I am beginner to fbprophet python.
I tried applying predict with and without the weekend data in source dataframe. Still this gives negative yhats in the prediction.
(Usually on weekends (St-Su), there is some non zero and non seasonal data points are recorded in original data.)

Could you please help me out how to fix this? Here is the screenshot:

image

@RSwarnkar if you don't have weekend data in the history, it is best to not make predictions for weekend dates in the future. So when you make the future dataframe of future dates to pass into m.predict(), just remove any weekend days from that dataframe. See #1291 for example code to do that.

I was looking at doing this in R and here's how you would do it:
future <- subset(future, as.POSIXlt(future$ds)$wday >= 1 & as.POSIXlt(future$ds)$wday < 6)

I am facing same problem in Python, model predicting for Saturday and Sunday even after running code

df_no_weekdays = future[future['ds'].dt.dayofweek < 5]

Capture

Capture1

@BHIMARAO1984 it looks like you called predict(future) instead of predict(df_no_weekdays).

Was this page helpful?
0 / 5 - 0 ratings

Related issues

L471 picture L471  Â·  3Comments

kimhale picture kimhale  Â·  3Comments

ahash52 picture ahash52  Â·  3Comments

andrew-pollock picture andrew-pollock  Â·  3Comments

annabednarska picture annabednarska  Â·  3Comments