Facebook Prophet ignores manually passed changepoints

68 Views Asked by At

I am trying to model some monthly data that has a clear COVID shock. I have already declared the COVID dates as holidays (Mar-Jul 2020), but the model does not seem to notice that there's an obvious trend slope change following COVID. I've tried passing using the Prophet(changepoints=) argument to pass in ['2020-02-01', '2020-08-01'], but the model just ignores the post-COVID changepoint. This produces a forecast that has a negative trend slope when it clearly should be at least flat is not slightly positive.

Can anyone help? Is there a way to force Prophet to use my changepoints?

Picture shows model output with the changepoints it used in red. Notice only the first one of the two entered in my code is being used by the model, when I had hoped there would be two red markers.

enter image description here enter image description here

Here's my code in case it helps:

import pandas as pd
from prophet import Prophet
from prophet.plot import plot_plotly, plot_components_plotly

data = pd.DataFrame( {{{ data + regressors }}} ). ### proprietary, I cannot share
addtl_regressors = ['regrA', 'regrB', 'regrC']

lockdowns = pd.DataFrame([{
    'holiday': 'COVID_1',
    'ds': '2020-03-01',
    'lower_window': 0,
    'ds_upper': '2020-07-02',  # 'ds_upper' is the end date of holiday
}])
for t_col in ['ds', 'ds_upper']:
    lockdowns[t_col] = pd.to_datetime(lockdowns[t_col])
lockdowns['upper_window'] = (lockdowns['ds_upper'] - lockdowns['ds']).dt.days

# instantiate model
m = Prophet(
    changepoints=['2020-02-01', '2020-08-01'],
    holidays=lockdowns,
    interval_width=0.8,
    uncertainty_samples=2000,
    changepoint_range=0.8,
    changepoint_prior_scale=0.05,
)

# add regressors to the model
for regressor in addtl_regressors:
    m.add_regressor(regressor, mode='additive')

# Fit the timeseries into Model
m.fit(data[['ds', 'y'] + addtl_regressors])

# make future DF with forecasts of each regressor
future = {{{ ANOTHER FUNCTION THAT CREATES VALUES OF REGRESSORS }}}

# make the forecast
forecast = m.predict(future)

# plot results with changepoints
plot_plotly(m, forecast, changepoints=True)
0

There are 0 best solutions below