--- title: Adapters for Prophet keywords: fastai sidebar: home_sidebar nb_path: "nbs/adapters.prophet.ipynb" ---
{% raw %}
2022-04-14 19:58:59 prophet.plot ERROR: Importing plotly failed. Interactive plots will not work.
{% endraw %} {% raw %}
{% endraw %} {% raw %}
import sys
{% endraw %} {% raw %}
sys.version_info >= (3, 7)
{% endraw %}

Arima

{% raw %}

class AutoARIMAProphet[source]

AutoARIMAProphet(growth='linear', changepoints=None, n_changepoints=25, changepoint_range=0.8, yearly_seasonality='auto', weekly_seasonality='auto', daily_seasonality='auto', holidays=None, seasonality_mode='additive', seasonality_prior_scale=10.0, holidays_prior_scale=10.0, changepoint_prior_scale=0.05, mcmc_samples=0, interval_width=0.8, uncertainty_samples=1000, stan_backend=None, d=None, D=None, max_p=5, max_q=5, max_P=2, max_Q=2, max_order=5, max_d=2, max_D=1, start_p=2, start_q=2, start_P=1, start_Q=1, stationary=False, seasonal=True, ic='aicc', stepwise=True, nmodels=94, trace=False, approximation=False, method=None, truncate=None, test='kpss', test_kwargs=None, seasonal_test='seas', seasonal_test_kwargs=None, allowdrift=False, allowmean=False, blambda=None, biasadj=False, parallel=False, num_cores=2, period=1) :: Prophet

Returns best ARIMA model using external variables created by the Prophet interface.

This class receives as parameters the same as prophet.Prophet and statsforecast.arima.AutoARIMA.

If your pipeline uses Prophet you can simply replace Prophet with AutoARIMAProphet and you'll be using AutoARIMA instead of Prophet.

{% endraw %} {% raw %}
{% endraw %}

Peyton Manning example

{% raw %}
df = pd.read_csv('https://raw.githubusercontent.com/facebook/prophet/main/examples/example_wp_log_peyton_manning.csv')
{% endraw %}

Without additional info

Usually, a Prophet pipeline without external regressors looks like this.

{% raw %}
m = Prophet()
m.fit(df)
future = m.make_future_dataframe(365)
forecast = m.predict(future)
fig = m.plot(forecast)
{% endraw %}

With the class AutoARIMAProphet you can simply replace Prophet and you'll be training an auto_arima model without changing the pipeline.

{% raw %}
%%capture
m = AutoARIMAProphet()
m.fit(df)
future = m.make_future_dataframe(365)
forecast = m.predict(future)
{% endraw %} {% raw %}
fig = m.plot(forecast)
{% endraw %}

With exogenous regressors provided by prophet

Usually Prophet pipelines include the usage of external regressors such as holidays.

{% raw %}
playoffs = pd.DataFrame({
  'holiday': 'playoff',
  'ds': pd.to_datetime(['2008-01-13', '2009-01-03', '2010-01-16',
                        '2010-01-24', '2010-02-07', '2011-01-08',
                        '2013-01-12', '2014-01-12', '2014-01-19',
                        '2014-02-02', '2015-01-11', '2016-01-17',
                        '2016-01-24', '2016-02-07']),
  'lower_window': 0,
  'upper_window': 1,
})
superbowls = pd.DataFrame({
  'holiday': 'superbowl',
  'ds': pd.to_datetime(['2010-02-07', '2014-02-02', '2016-02-07']),
  'lower_window': 0,
  'upper_window': 1,
})
holidays = pd.concat((playoffs, superbowls))
{% endraw %} {% raw %}
%%capture
m = Prophet(holidays=holidays)
m.add_country_holidays(country_name='US')
m.fit(df)
future = m.make_future_dataframe(365)
forecast = m.predict(future)
{% endraw %} {% raw %}
fig = m.plot(forecast)
{% endraw %}

The class AutoARIMAProphet allows you to handle these scenarios to fit an auto_arima model with exogenous variables.

{% raw %}
%%capture
m = AutoARIMAProphet(holidays=holidays)
m.add_country_holidays(country_name='US')
m.fit(df)
future = m.make_future_dataframe(365)
forecast = m.predict(future)
{% endraw %} {% raw %}
fig = m.plot(forecast)
{% endraw %}