Prophet includes functionality for time series cross validation to measure forecast error using historical data. This is done by selecting cutoff points in the history, and for each of them fitting the model using data only up to that cutoff point. We can then compare the forecasted values to the actual values. This figure illustrates a simulated historical forecast on the Peyton Manning dataset, where the model was fit to a initial history of 5 years, and a forecast was made on a one year horizon.
The Prophet paper gives further description of simulated historical forecasts.
This cross validation procedure can be done automatically for a range of historical cutoffs using the
cross_validation function. We specify the forecast horizon (
horizon), and then optionally the size of the initial training period (
initial) and the spacing between cutoff dates (
period). By default, the initial training period is set to three times the horizon, and cutoffs are made every half a horizon.
The output of
cross_validation is a dataframe with the true values
y and the out-of-sample forecast values
yhat, at each simulated forecast date and for each cutoff date. This dataframe can then be used to compute error measures of
1 2 3
# R df.cv <- cross_validation(m, horizon = 730, units = 'days') head(df.cv)
1 2 3 4
# Python from fbprophet.diagnostics import cross_validation df_cv = cross_validation(m, horizon = '730 days') df_cv.head()