--- layout: docs docid: "diagnostics" title: "Diagnostics" permalink: /docs/diagnostics.html --- 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](https://peerj.com/preprints/3190.pdf) 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 `yhat` vs. `y`. ```R # R df.cv <- cross_validation(m, horizon = 730, units = 'days') head(df.cv) ``` ```python # Python from fbprophet.diagnostics import cross_validation df_cv = cross_validation(m, horizon = '730 days') df_cv.head() ```
| ds | yhat | yhat_lower | yhat_upper | y | cutoff | |
|---|---|---|---|---|---|---|
| 0 | 2014-01-21 | 9.439510 | 8.799215 | 10.080240 | 10.542574 | 2014-01-20 |
| 1 | 2014-01-22 | 9.267086 | 8.645900 | 9.882225 | 10.004283 | 2014-01-20 |
| 2 | 2014-01-23 | 9.263447 | 8.628803 | 9.852847 | 9.732818 | 2014-01-20 |
| 3 | 2014-01-24 | 9.277452 | 8.693226 | 9.897891 | 9.866460 | 2014-01-20 |
| 4 | 2014-01-25 | 9.087565 | 8.447306 | 9.728898 | 9.370927 | 2014-01-20 |