Automatic forecasting procedure for time series data with strong seasonal effects and multiple seasons of historical data
—
Helper functions for analyzing regressor coefficients, extracting model parameters, and supporting advanced Prophet model introspection and warm-starting capabilities.
Functions for analyzing the impact and coefficients of external regressors.
def regressor_coefficients(m):
"""
Summarize regressor coefficients with confidence intervals.
Parameters:
- m: Prophet, fitted Prophet model with regressors
Returns:
- DataFrame with regressor names, coefficients, and confidence intervals
"""
def regressor_index(m, name):
"""
Get the column index of a regressor in the beta matrix.
Parameters:
- m: Prophet, fitted Prophet model
- name: str, name of the regressor
Returns:
- int, column index of the regressor in model parameters
"""Extract parameters for warm-starting new models or advanced analysis.
def warm_start_params(m):
"""
Retrieve parameters from a fitted model for warm-starting a new model.
Parameters:
- m: Prophet, fitted Prophet model
Returns:
- dict, dictionary of parameters that can be used to initialize a new model
"""from prophet import Prophet
from prophet.utilities import regressor_coefficients, regressor_index
# Create model with regressors
model = Prophet()
model.add_regressor('temperature')
model.add_regressor('humidity')
# Fit model with regressor data
model.fit(df_with_regressors)
# Analyze regressor coefficients
coeffs = regressor_coefficients(model)
print(coeffs)
# Output shows coefficient estimates and confidence intervals
# Get specific regressor index
temp_idx = regressor_index(model, 'temperature')
print(f"Temperature regressor is at index: {temp_idx}")from prophet.utilities import warm_start_params
# Train initial model
model1 = Prophet()
model1.fit(training_data)
# Extract parameters for warm start
params = warm_start_params(model1)
# Create new model with similar configuration
model2 = Prophet(
changepoint_prior_scale=model1.changepoint_prior_scale,
seasonality_prior_scale=model1.seasonality_prior_scale
)
# The warm start parameters can be used to initialize
# the new model's internal state for faster fitting
model2.fit(extended_training_data)# Examine all regressor effects
if model.extra_regressors:
print("Model has external regressors:")
for name, regressor_info in model.extra_regressors.items():
idx = regressor_index(model, name)
print(f" {name}: index {idx}, mode {regressor_info['mode']}")
# Get coefficient summary
coeff_summary = regressor_coefficients(model)
print("\nRegressor Coefficients:")
print(coeff_summary)
else:
print("Model has no external regressors")Install with Tessl CLI
npx tessl i tessl/pypi-prophet