'How to retrieve trained Hyperparameters in Facebook Prophet (Python)?

I want to retrieve the hyperparameters after training a time-series model using Facebook Prophet, so that I can use the learned values in a second model.

Here's what I tried.

    from prophet import Prophet

    # Train the first DataFrame
    m1 = Prophet() # initialized with default parameters
    m1.fit(df1)
    future = m1.make_future_dataframe(periods=365)
    forecast = m1.predict(df1)

    m2 = Prophet(
        daily_seasonality = m1.daily_seasonality,
        weekly_seasonality = m1.weekly_seasonality,
        yearly_seasonality = m1.yearly_seasonality,
        seasonality_prior_scale = m1.seasonality_prior_scale,
        changepoint_prior_scale = m1.changepoint_prior_scale,
        uncertainty_samples = m1.uncertainty_samples,
        seasonality_mode = m1.seasonality_mode,
        interval_width = m1.interval_width,
        n_changepoints = m1.n_changepoints,
    ) # initialized with trained parameters from m1

    # Train the second DataFrame
    m2.fit(df2)

However, when I try debugging the hyparameter values, it looks like m2 is initialized with the same values m1 was initialized with.

How do I get the trained parameters from m1?



Solution 1:[1]

You can use MLFlow for the purpose.

import mlflow
from prophet import Prophet, serialize
def extract_params(pr_model):
    return {attr: getattr(pr_model, attr) for attr in serialize.SIMPLE_ATTRIBUTES}

mlflow.log_params(params)    
m1_params = extract_params(m1)

Afterward it should be simple to set the m2 hyper parameters with the m1 ones.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Mahdi