Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to extract seasonal trends from Prophet

I have been using Prophet from Facebook and so far it has been produced some great results.

Having looked in the docs and googling, there doesn't seem to be an automatic way to extract the seasonal trends from a model as a dataframe or a dict, e.g.:

weekly_trends = { 1 : monday_trend, 2 : tuesday_trend, ... , 7 : sunday_trend } 

yearly_trends = { 1 : day_1_trend, 2 : day_2_trend, ... , 365 : day_365_trend } 

Currently I can extract these out using a more manual way but was just wondering if I had missed something more elegant?

like image 362
Matt Avatar asked Nov 28 '17 14:11

Matt


People also ask

What is seasonality in Prophet model?

Prophet will by default fit weekly and yearly seasonalities, if the time series is more than two cycles long. It will also fit daily seasonality for a sub-daily time series. You can add other seasonalities (monthly, quarterly, hourly) using the add_seasonality method (Python) or function (R).

Is Facebook Prophet any good?

Accurate and fast. Prophet is used in many applications across Facebook for producing reliable forecasts for planning and goal setting. We've found it to perform better than any other approach in the majority of cases.

What algorithm does Fbprophet use?

Prophet is an additive regression model with a piecewise linear or logistic growth curve trend. It includes a yearly seasonal component modeled using Fourier series and a weekly seasonal component modeled using dummy variables. For more information, see Prophet: forecasting at scale .

What are seasonal trends?

Seasonality refers to predictable changes that occur over a one-year period in a business or economy based on the seasons including calendar or commercial seasons. Seasonality can be used to help analyze stocks and economic trends.


2 Answers

The trained model dataframe has all the seasonal, trend and holidays information. - take a look at its columns. Here's how to look into it in Python:

m = Prophet()
m.fit(ts)
future = m.make_future_dataframe()
forecast = m.predict(future)
print(forecast['weekly'])

Take any 7 days out of that series. That will give you the scale of the additive weekly adjustment for each weekday. Similar for the yearly seasonality.

like image 151
Alexandr Matsenov Avatar answered Sep 22 '22 20:09

Alexandr Matsenov


You can specify daily, weekly, and yearly seasonality during model fit

    m = Prophet(changepoint_prior_scale=0.01, weekly_seasonality=False, holidays=holidays, interval_width=0.90, yearly_seasonality=True, mcmc_samples=300)
    m.add_seasonality(name='weekly', period=7, fourier_order=3)
    m.add_seasonality(name='monthly', period=30.5, fourier_order=8)
    m.fit(X)
like image 42
1dhiman Avatar answered Sep 23 '22 20:09

1dhiman