Prophet Learning (4) Trend Changepoints

Table of contents

Trend Changepoints (Trend Changepoints)

Automatic changepoint detection in Prophet

Adjusting trend flexibility

Specifying the locations of the changepoints


Trend Changepoints (Trend Changepoints)

You may have noticed that in the examples earlier in this document, the trajectories of the real-time series were frequently mutated. By default, Prophet will automatically detect these change points and allow the trend to adapt appropriately. However, if you wish to have finer control over this process (e.g. Prophet misses a rate change, or overfits rate changes in history), then you can use several input parameters.

Automatic changepoint detection in Prophet

Prophet detects change points by first specifying a large number of potential change points that allow rate changes. It then places a sparse prior (equivalent to L1 regularization) on the magnitude of the rate change - this essentially means that the Prophet has a large number of possible places where the rate could change, but uses as few as possible. Check out Peyton Manning's predictions in Quick Start. By default, Prophet specifies 25 potential change points that are placed uniformly in the top 80% of the time series. The vertical lines in the graph indicate where to place potential change points:

 Although we have many places where the rate could change, most of these change points are not used due to the sparse prior. We can see this by plotting the magnitude of the rate of change for each change point:

 The number of potential change points can be set with the parameter n_changepoints, but can be better tuned by adjusting the regularization. The location of the point of change of meaning can be visualized by:

# Python
from prophet.plot import add_changepoints_to_plot
fig = m.plot(forecast)
a = add_changepoints_to_plot(fig.gca(), m, forecast)

 By default, only the first 80% of change points of the time series are extrapolated to allow enough runway to predict future trends and avoid overfitting fluctuations at the end of the time series. This default works in many cases, but not all, and can be changed using the changepoint_range parameter. For example, m = Prophet(changepoint_range=0.9) or m <- Prophet(changepoint . range=0.9) in Python. range = 0.9) in R will place potential change points in the first 90% of the time series.

Adjusting trend flexibility

If the trend changes are overfitting (too much flexibility) or underfitting (not enough flexibility), you can adjust the strength of the sparse prior with the input parameter changepoint_prior_scale. By default, this parameter is set to 0.05. Increasing it will make the trend more flexible:

# Python
m = Prophet(changepoint_prior_scale=0.5)
forecast = m.fit(df).predict(future)
fig = m.plot(forecast)

 Reducing it makes the trend less flexible:

# Python
m = Prophet(changepoint_prior_scale=0.001)
forecast = m.fit(df).predict(future)
fig = m.plot(forecast)

 When visualizing forecasts, this parameter can be adjusted as needed if the trend seems excessive or out of place. In a fully automated setting, see the documentation on cross-validation for advice on how to tune this parameter.

Specifying the locations of the changepoints

If you wish, you can manually specify the location of potential changepoints using the changepoints parameter instead of using automatic changepoint detection. Slope changes will then only be allowed at these points, sparsely regularized as before. For example, one could create a grid of points like the autocomplete does, but then augment the grid with some specific dates known to be likely to change. As another example, changepoints can be completely restricted to a small set of dates, like so:

# Python
m = Prophet(changepoints=['2014-01-01'])
forecast = m.fit(df).predict(future)
fig = m.plot(forecast)

 

Guess you like

Origin blog.csdn.net/weixin_64338372/article/details/130119477