Skip to content

Integrate with Prophet

Facebook Prophet is a fast forecasting procedure for time series (calendar) data that provides complete automated forecasts that can be further tuned by hand.

import comet_ml

import os
import pandas as pd
from fbprophet import Prophet
from fbprophet.diagnostics import cross_validation
from fbprophet.plot import plot_cross_validation_metric

experiment = comet_ml.Experiment()

df = pd.read_csv("example_wp_log_peyton_manning.csv")

m = Prophet()
# Your training code
m.fit(df)

Open In Colab

Log automatically

When you run Facebook Prophet with Comet, the following items are automatically logged:

  • Hyperparameters
  • Model
  • Figures

Configure Comet for Prophet

Prophet codeWhat is automatically loggedHow to control
Prophet()logs all hyperparametersExperiment(auto_param_logging=True)
model.fit()logs modelExperiment(log_graph=True)
cross_validation()logs items logged with model.fit()Experiment(log_graph=True)
plot()logs matplotlib figureCOMET_AUTO_LOG_FIGURES=1 or in ~/.comet.config
plot_components()logs matplotlib figureCOMET_AUTO_LOG_FIGURES=1 or in ~/.comet.config
plot_cross_validation_metric()logs matplotlib figureCOMET_AUTO_LOG_FIGURES=1 or in ~/.comet.config

You can control each of these by setting the Experiment argument to False or the config variable to 0.

End-to-end example

import comet_ml

import os
import pandas as pd
from prophet import Prophet
from prophet.diagnostics import cross_validation
from prophet.plot import plot_cross_validation_metric

experiment = comet_ml.Experiment(
    api_key="<Your API Key>",
    project_name="<Your Project Name>"
)

# You will need to download this file from
# https://raw.githubusercontent.com/facebook/prophet/main/examples/example_wp_log_peyton_manning.csv
df = pd.read_csv('./example_wp_log_peyton_manning.csv')

model = Prophet()
model.fit(df)

future = model.make_future_dataframe(periods=365)
forecast = model.predict(future)

df_cv = cross_validation(model, initial="730 days", period="180 days", horizon="365 days")
plot_cross_validation_metric(df_cv, "mse")

Note

There are alternatives to setting the API key programatically. See more here.

Try it out!

Here is an example for using Comet with Prophet.

Open In Colab

Aug. 3, 2022