Skip to content

Advanced features Prophet

Prudhvi Koushal edited this page Mar 6, 2018 · 1 revision

This page is about the advanced features of Prophet, that I found from their github implementation code and comments.

  • Overview
    • Cross-validation
    • Outliers
    • Forecasting Growth
    • Seasonality effects
    • Holidays
    • Trend changepoints
    • Uncertainty intervals
      • Uncertainty in trend
      • Uncertainty in seasonality

Cross - validation

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.

Outliers

The best way to handle outliers is to remove them - Prophet has no problem with missing data. If you set their values to NA in the history but leave the dates in future, then Prophet will give you a prediction for their values.

Forecasting Growth

Prophet uses a linear model for its forecast. When forecasting growth, there is usually some maximum achievable point: total market size, total population size, etc. This is called the carrying capacity, and the forecast should saturate at this point.

Prophet allows you to make forecasts using a logistic growth trend model, with a specified carrying capacity.

We must specify the carrying capacity in a column 'cap'. Here we will assume a particular value, but this would usually be set using data or expertise about the market size.

Remember that cap must be specified for each row of the dataframe. Cap need not be a constant, it can be an increasing sequence. To use the logistic growth instead of the linear growth, we need to specify the growth parameter of the Prophet class as logistic. Remember to add the cap column to both the df and the future.

Similarly, we can specify a minimum value. This is done by adding a column to floor (both to df and future). One more key thing to note is that, to use a saturating minimum, the cap value must also be specified.

Seasonality Effects

Prophet will by default fit weekly and yearly seasonalities. Other seasonalities like monthly, quarterly, hourly using the add _seasonality method. The inputs to this function are a name, the period of the seasonality in days, and the number of Fourier terms for the seasonality. Increasing the number of Fourier terms allows the seasonality to fit faster changing cycles, but can also lead to overfitting.

Holidays

If you have holidays or other recurring events that you'd like to model, you must create a dataframe for them. It has two columns (holiday and ds) and a row for each occurrence of the holiday. It must include all occurrences of the holiday, both in the past (back as far as the historical data go) and in the future (out as far as the forecast is being made). If they won't repeat in the future, Prophet will model them and then not include them in the forecast. Now simply pass this created holidays dataframe to the argument holidays of the Prophet class.

Trend Changepoints

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.

Uncertainty intervals

By default Prophet will return uncertainty intervals for the forecast yhat. There are several important assumptions behind these uncertainty intervals. There are three sources of uncertainty in the forecast: uncertainty in the trend, uncertainty in the seasonality estimates, and additional observation noise.

Uncertainty in trend:

Future trend changes. Time series usually have a trend changes, which can be observed in the historical data. Prophet fits to these trend changes, but the important point is which trend changes should we expect to be moving forward. Of course, we do not know the answer for this question, but we intend to find the most reasonable answer. This answer often is based on the assumption that future will see similar trend changes as history. The answer is to project the trend changes forward and by computing their distribution we obtain uncertainty levels.

Uncertainty in seasonality

By default, prophet does not return uncertainty in seasonality. To model the uncertainty from seasonality, we need to pass the argument mcmc_samples of the Prophet class. This will use MCMC sampling instead of MAP estimation and takes lot more time.

For code details of the above features, refer to Prophet project on github.

Clone this wiki locally