prophet: Getting regression coefficients for additional regressors
Hi, How can I get the regression coefficients for additional regressors added in prophet. I am using the below code, using two regressors. If I look at beta values in params, it has 28 values. Is it possible to get regression coefficients from them?
m = Prophet(changepoint_prior_scale=cp,
weekly_seasonality=False, daily_seasonality=False)
m.add_seasonality(name='monthly', period=30, fourier_order=3)
m.add_regressor('Price per Unit')
m.add_regressor('Promo_present')
About this issue
- Original URL
- State: closed
- Created 5 years ago
- Reactions: 1
- Comments: 20 (6 by maintainers)
Something to note: As of #1572, there is now in Python a utility for correctly extracting the regression coefficients of a model. This utility has shipped with v0.7.1 now in PyPI: https://github.com/facebook/prophet/blob/77da5b8c06d05d478af510198c685d454342db1f/python/fbprophet/utilities.py#L28
It is used like:
It will properly account for all of the standardization happening under the hood.
@carrasq for your specific questions:
yis stored inm.y_scaleand the standardization (mean and std) for each regressor is stored in them.extra_regressorsdict.@AnupaS that is right, there are 26 coefficients for seasonality and 2 for the extra regressor. To see which coefficients correspond to which components, you can look at
m.train_component_cols. This is a dataframe with 28 rows (one for each of the coefficients), and each column is a component (and is named for that component). The value in the dataframe is 1 if that beta is involved in that component, and 0 otherwise. For example, weekly seasonality uses 6 coefficients, and so you will see that the ‘weekly’ column has 6 1s. The extra regressors will use 1 each, and so you will find for their columns the one row that has a 1, and that is the index of the beta you want.An important thing to note when looking at the regression coefficients is that Prophet does a lot of data normalization prior to model fitting. The
ydata that is giving in fit is scaled by its max value. Extra regressor columns are also by default standardized (that is, subtract mean, divide by sd) if non-binary. So the coefficient value that you see will be one that is applied to the standardized values of the extra regressors, and then added to the scaled trend forecast. The raw values of the coefficients thus may not be that useful to you.Hi,
Just want to clarify and make sure I completely understand this. The code is written in R language.
I have included 6 regressors in the model.
m = prophet() %>% add_regressor(‘no_hours_open’) %>% add_regressor(‘easter_fri_indc’) %>% add_regressor(‘easter_sat_indc’) %>% add_regressor(‘easter_sun_indc’) %>% add_regressor(‘easter_mon_indc’) %>% add_regressor(‘anzac_day_indc’) %>% fit.prophet(dat)
The model returns 12 coefficients.
And also > as.matrix(m$train.component.cols) returns a matrix with 12 rows and 10 columns.
To obtain the coefficients, I use the following:
Am I on the right track?
@AmbikaSowmyan can you check what version of fbprophet you’re using? It will be there for 0.7 and later.
I’m guessing it’s old, in which case you should upgrade (and note that for the latest version the package name has changed to
prophet)