# Trend Changepoints

You may have noticed in the earlier examples in this documentation that real time series frequently have abrupt changes in their trajectories. By default, Prophet will automatically detect these changepoints and will allow the trend to adapt appropriately. However, if you wish to have finer control over this process (e.g., Prophet missed a rate change, or is overfitting rate changes in the history), then there are several input arguments you can use.

### Automatic changepoint detection in Prophet

Prophet detects changepoints by first specifying a large number of *potential changepoints* at which the rate is allowed to change. It then puts a sparse prior on the magnitudes of the rate changes (equivalent to L1 regularization) - this essentially means that Prophet has a large number of *possible* places where the rate can change, but will use as few of them as possible. Consider the Peyton Manning forecast from the Quickstart. By default, Prophet specifies 25 potential changepoints which are uniformly placed in the first 80% of the time series. The vertical lines in this figure indicate where the potential changepoints were placed:

Even though we have a lot of places where the rate can possibly change, because of the sparse prior, most of these changepoints go unused. We can see this by plotting the magnitude of the rate change at each changepoint:

The number of potential changepoints can be set using the argument `n_changepoints`

, but this is better tuned by adjusting the regularization.

### Adjusting trend flexibility

If the trend changes are being overfit (too much flexibility) or underfit (not enough flexibility), you can adjust the strength of the sparse prior using the input argument `changepoint_prior_scale`

. By default, this parameter is set to 0.05. Increasing it will make the trend *more* flexible:

1 2 3 4 | # R m <- prophet(df, changepoint.prior.scale = 0.5) forecast <- predict(m, future) plot(m, forecast); |

1 2 3 4 | # Python m = Prophet(changepoint_prior_scale=0.5) forecast = m.fit(df).predict(future) m.plot(forecast); |

Decreasing it will make the trend *less* flexible:

1 2 3 4 | # R m <- prophet(df, changepoint.prior.scale = 0.001) forecast <- predict(m, future) plot(m, forecast); |

1 2 3 4 | # Python m = Prophet(changepoint_prior_scale=0.001) forecast = m.fit(df).predict(future) m.plot(forecast); |

### Specifying the locations of the changepoints

If you wish, rather than using automatic changepoint detection you can manually specify the locations of potential changepoints with the `changepoints`

argument.

1 2 3 4 | # R m <- prophet(df, changepoints = c('2014-01-01')) forecast <- predict(m, future) plot(m, forecast); |

1 2 3 4 | # Python m = Prophet(changepoints=['2014-01-01']) forecast = m.fit(df).predict(future) m.plot(forecast); |