facebook / prophet

Tool for producing high quality forecasts for time series data that has multiple seasonality with linear or non-linear growth.
https://facebook.github.io/prophet
MIT License
18.46k stars 4.53k forks source link

How to interpret prophet coefficients #928

Closed ruksarsultana closed 5 years ago

ruksarsultana commented 5 years ago

I'm trying to derive elasticities using the coefficients of regressors/ independent variables in prophet. How should the prophet coefficients be interpreted?

If the coefficient for a regressor is beta using prophet model, does it imply 1% increase in regressor results on an average beta % increase in dependent variable/ y. Please note that there is NO log transformation done on both X & Y in this case.

Also attached the model coefficients by fitting Prophet & ARIMAX models. How can I combine the coefficients of both the models (Prophet & ARIMAX) to arrive at a combined elasticity for each of the independent variables (GDPL & LRAT)

Model_Parameters

bletham commented 5 years ago

The model is

additive:       y(t) = trend(t) + seasonality(t) + beta * regressor(t)
multiplicative: y(t) = (1 + seasonality(t) + beta * regressor(t)) * trend(t)

The quantity beta * regressor(t) is outputed in the forecast dataframe, as the component for that regressor.

For an additive model, it can be interpreted as increasing regressor(t) by 1 unit increases y(t) by beta units. For multiplicative, increasing regressor(t) by 1 unit increases y(t) by trend(t) units.

There isn't a totally direct relationship between these and elasticity, but I hope from these formulae you can compute the quantity you are trying to estimate.

beta is best computed by dividing the column in the forecast dataframe by the regressor, since the beta that is stored internally on the model object incorporates a whole bunch of data transforms that are done prior to fitting the model, and so isn't directly useful.

yeqiaoling commented 5 years ago

Thank you for showing how to compute the beta. However, I had questions while computing the beta. I made up the following numbers, but the pattern is what I observed in my model fitting.

Suppose my regressor x = [0,0, ..., 0,10]. After fitting Prophet model, I had the corresponding column in the forecast dataframe is c =[1000, 1000, ..., 1000, -2000]. How could I calculate the beta?

bletham commented 5 years ago

I neglected to say that the regressor is by default standardized prior to model fitting. This means that what is actually shown is beta (X - mean(X)) / std(X) So if you could back it out from there, or if you want it to be just betaX you can turn of standardization (it is one of the options to add_regressor)

yeqiaoling commented 5 years ago

Thank you!

yeqiaoling commented 5 years ago

I have a quick question: is y standardized as well before fitting the model?

bletham commented 5 years ago

Y is scaled by its maximum (absolute) value. That happens here: https://github.com/facebook/prophet/blob/master/python/fbprophet/forecaster.py#L285