Facebook Prophet ignores manually passed changepoints
- Dominant language
- Python
- Stars
- 20.4k
- Forks
- 4.6k
- Avg merge
- 19h 52m
- Merged PRs (30d)
- 1
Description
reposted from [StackOverflow post](https://stackoverflow.com/questions/77614585/facebook-prophet-ignores-manually-passed-changepoints).
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?
I am using `prophet==1.1.5` in a Python 3.9.7 environment on a MacBook Pro that uses an M1 chip.
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.


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)
```
Contributor guide
Assessment
This issue has not been assessed yet.