Prophet: Monthly Seasonality: How to incorporate ?

Created on 1 Jun 2017  Â·  20Comments  Â·  Source: facebook/prophet

Hi,
My time series data has weekly as well as monthly seasonality i.e. sales tends to be higher on weekends and again same is applied for month end also. However my time series doesn't have yearly seasonality. How do i incorporate these changes ? Please explain.

enhancement ready

Most helpful comment

We'd like to add a method for adding arbitrary seasonalities, something like:

m.add_seasonality(period=30.4, components=5, name='monthly')

You can see right here where we can easily generate the corresponding X matrix for a specified period and number of components: https://github.com/facebookincubator/prophet/blob/master/R/R/prophet.R#L387

It shouldn't be too much effort to add this functionality.

All 20 comments

We'd like to add a method for adding arbitrary seasonalities, something like:

m.add_seasonality(period=30.4, components=5, name='monthly')

You can see right here where we can easily generate the corresponding X matrix for a specified period and number of components: https://github.com/facebookincubator/prophet/blob/master/R/R/prophet.R#L387

It shouldn't be too much effort to add this functionality.

I feel compelled to write an endorsement for this enhancement, which would make forecast immensely more valuable for sales forecasting. I could definitely convince my company to use prophet in much of our sales analytics if this feature were added. Do you need any help with developing it given your other priorities?

I would definitely accept a PR for this :-)

@bletham When to release a new version?

@fanlu I don't have a good timeline for the next version atm.

Along the same note, I would like to see hourly seasonality, It's the strongest in my data compared to day of week or month

I took a horrible stab at trying to add it but unfortunately I don't know what I'm doing for python plotting. If someone who actually knows what they're doing, I think my PR for hourly is really close. https://github.com/facebookincubator/prophet/pull/235

This is now pushed to the v0.2 branch. https://github.com/facebookincubator/prophet/commit/8be35c2f34a41b653e3966bb6a5391aefc6554f8 and https://github.com/facebookincubator/prophet/commit/707c88527593bd65f02e99e03704bf84545495d1 add a method/function add_seasonality for adding a custom seasonality. See the example here for using monthly seasonality:
https://github.com/facebookincubator/prophet/blob/v0.2/notebooks/seasonality_and_holiday_effects.ipynb

Install the v0.2 branch from github and try it out!
In R you can use

devtools::install_github('facebookincubator/prophet', subdir='R', ref='v0.2')

@bletham How to use python version?

Download the v0.2 zip here: https://github.com/facebookincubator/prophet/archive/v0.2.zip
Then in the python directory, run

python setup.py install

use v0.2 zip
/Users/lonica/anaconda3/envs/py2/lib/python2.7/site-packages/fbprophet-0.1.1-py2.7.egg/fbprophet/forecaster.py in add_seasonality(self=, name='monthly', period=30.5, fourier_order=5)
355 name: string name of the seasonality component.
356 period: float number of days in one period.
357 fourier_order: int number of Fourier components to use.
358 """
359 if self.holidays is not None:
--> 360 if name in set(holidays['holiday']):
name = 'monthly'
361 raise ValueError(
362 'Name "{}" already used for holiday'.format(name))
363 self.seasonalities[name] = (period, fourier_order)
364

NameError: global name 'holidays' is not defined

I am a bit curious. Could the monthly seasonality be handled by the yearly seasonality? To me, monthly seasonality can be imposed by using yearly seasonality with shorter period, right?

I'd expect that most monthly seasonality would be picked up by the yearly seasonality. However, the seasonality model is essentially a low-pass filter, which means if the monthly variation is high-frequency enough the built-in yearly wouldn't be able to fit it. This new method would allow you to customize things to make it work, in the case of a strong monthly-repeating cycle, by adding a specific monthly seasonality.

@bletham That makes sense, as yearly seasonality (at least in the current implementation) models very smooth change over the year. Thanks!

Guys,
I am not able to install v0.2 in python. After installing as @bletham suggested I am getting error (FileNotFoundError: [Errno 2] No such file or directory: '/home/vaibhavkaushal/anaconda3/pkgs/prophet-0.2/python/fbprophet/stan_models/linear_growth.pkl') upon importing fbprophet in python.

Am i doing anything wrong ? I guess not, then how do i incoporate it ? Also when this update going live officially ?

It looks like the model files weren't built during install (or, weren't installed to the right place). There weren't any errors/warning during install? I'm not that familiar with Anaconda and don't know if there are any special considerations for installing from source. Does anyone else know?

This will be pushed to pip as part of the v0.2 update that will be coming as soon as we wrap up a few other features. I am expecting around 5 weeks.

No, there is no error during install. It was a clean install. It only throws error once you try to import it. 5 weeks is a long time, i think i should figure out a way to wirk it up! Can anyone help ?

So, I was able to fix this by copying the expected files into the Path the interpreter expected to find them. A little hack-y, but it looks like it worked!

This is now available in CRAN and pypi. Documentation is here:
https://facebookincubator.github.io/prophet/docs/seasonality_and_holiday_effects.html

If you have any issues with it feel free to post here or open a new issue.

Was this page helpful?
0 / 5 - 0 ratings