1

I have a feeling this is more of a basic python question, but I'm struggling to find an answer on how to reference these additive regression components.

The FB Prophet documentation says to build a parameter grid with all of the setting configurations that you want to pass iteratively into the model to determine the combination that generates the lowest amount of error, which I have done (partially):

param_grid = {  
                'changepoint_prior_scale': [[0.005, .01, 0.05, 0.5, 1, 5, 10, 20, 30, 40, 50, 60, 70, 80 ,90, 100],
                'changepoint_range': [0.8, 0.9],
                'holidays_prior_scale':[[0.005, .01, 0.05, 0.5, 1, 5, 10, 20, 30, 40, 50, 60, 70, 80 ,90, 100]],
                'seasonality_mode': ['multiplicative', 'additive'],
                'growth': ['linear', 'logistic'],
                
              }

Facebook documentation here for reference: https://facebook.github.io/prophet/docs/diagnostics.html#hyperparameter-tuning

The documentation only explains how to hyperparameter tune the standard python model features, there are no examples for how to pass iterative parameters for "added" regression features that the Prophet model supports.

Here's an example of my relevant code:

M = Prophet(
    growth='linear',
    #interval_width=0.80,
    seasonality_mode= 'multiplicative',
    daily_seasonality=False,
    weekly_seasonality=False,
    yearly_seasonality=False,
    holidays=Holidays
    ).add_seasonality(
        name='monthly',
        period=30.5,
        fourier_order=50,#25
        prior_scale=20
    ).add_seasonality(
        name='daily',
        period=1,
        fourier_order=70,#25
        prior_scale=20
    ).add_seasonality(
        name='weekly',
        period=7,
        fourier_order=50,
        prior_scale=60
    ).add_seasonality(
        name='yearly',
        period=365.25,
        fourier_order= 30)

I'm wondering how to appropriately refer to something like "Monthly Fourier_Order" and "Monthly Prior_Scale" in my parameter grid. I tried Monthly.fourier_order and it didn't work.

I'm assuming this is probably a basic python referencing problem vs something Prophet specific. I'm just not sure how to correctly reference these additive features.

Any help would be appreciated.

t25
  • 167
  • 3
  • 14

2 Answers2

1
m = Prophet(weekly_seasonality=False)
m.add_seasonality(name='monthly', period=30.5, fourier_order=5)
forecast = m.fit(df).predict(future)
fig = m.plot_components(forecast)

ref link : https://facebook.github.io/prophet/docs/seasonality,_holiday_effects,_and_regressors.html

jani basha
  • 11
  • 2
0

It looks like you are lookin for seasonal parameters to enter, but there doesn't seem to be a monthly seasonal component. I'm not sure you could add one using the add_seasonality(name='monthly', period=30.5, fourier_order=5) method since that is added after the model is created and the param_grid loop through the parameters of the model.

Try:

 param_grid = {  
'changepoint_prior_scale': [0.001, 0.01, 0.1, 0.5],
'seasonality_prior_scale': [0.01, 0.1, 1.0, 10.0],
'seasonality_mode': ['multiplicative', 'additive'],
'growth': ['linear', 'logistic'],
'yearly_seasonality':[5,10,20,40],
'weekly_seasonality':[5,10,20,40],
'daily_seasonality':[5,10,20,40],
}

Here are all the parameters available based on the source code from the Prophet GitHub:

  • Parameters
    • growth: String 'linear', 'logistic' or 'flat' to specify a linear, logistic or flat trend.
    • changepoints: List of dates at which to include potential changepoints. If not specified, potential changepoints are selected automatically.
    • n_changepoints: Number of potential changepoints to include. Not used if input changepoints is supplied. If changepoints is not supplied, then n_changepoints potential changepoints are selected uniformly from the first changepoint_range proportion of the history.
    • changepoint_range: Proportion of history in which trend changepoints will be estimated. Defaults to 0.8 for the first 80%. Not used if changepoints is specified.
    • yearly_seasonality: Fit yearly seasonality. Can be 'auto', True, False, or a number of Fourier terms to generate.
    • weekly_seasonality: Fit weekly seasonality. Can be 'auto', True, False, or a number of Fourier terms to generate.
    • daily_seasonality: Fit daily seasonality. Can be 'auto', True, False, or a number of Fourier terms to generate.
    • holidays: pd.DataFrame with columns holiday (string) and ds (date type) and optionally columns lower_window and upper_window which specify a range of days around the date to be included as holidays. lower_window=-2 will include 2 days prior to the date as holidays. Also optionally can have a column prior_scale specifying the prior scale for that holiday.
    • seasonality_mode: 'additive' (default) or 'multiplicative'.
    • seasonality_prior_scale: Parameter modulating the strength of the seasonality model. Larger values allow the model to fit larger seasonal fluctuations, smaller values dampen the seasonality. Can be specified for individual seasonalities using add_seasonality.
    • holidays_prior_scale: Parameter modulating the strength of the holiday components model, unless overridden in the holidays input.
    • changepoint_prior_scale: Parameter modulating the flexibility of the automatic changepoint selection. Large values will allow many changepoints, small values will allow few changepoints.
    • mcmc_samples: Integer, if greater than 0, will do full Bayesian inference with the specified number of MCMC samples. If 0, will do MAP estimation.
    • interval_width: Float, width of the uncertainty intervals provided for the forecast. If mcmc_samples=0, this will be only the uncertainty in the trend using the MAP estimate of the extrapolated generative model. If mcmc.samples>0, this will be integrated over all model parameters, which will include uncertainty in seasonality.
    • uncertainty_samples: Number of simulated draws used to estimate uncertainty intervals. Settings this value to 0 or False will disable uncertainty estimation and speed up the calculation.
    • stan_backend: str as defined in StanBackendEnum default: None - will try to iterate over all available backends and find the working one
baldwibr
  • 189
  • 7