Skip to content

Working with Prophet#

Open in Colab

Custom dashboard displaying metadata logged with Prophet

Prophet is a popular time-series forecasting library.

With the Neptune–Prophet integration, you can keep track of parameters, forecast data frames, residual diagnostic charts, cross-validation folds, and other metadata while training models with Prophet.

See in Neptune  Code examples 

Related

Before you start#

Installing the Neptune-Prophet integration#

pip install neptune-prophet

Logging options#

In order to track the metadata to Neptune, you need to initialize a Neptune run.

import neptune.new as neptune
run = neptune.init_run()
Haven't registered?

If you haven't registered or set up your credentials, you can log anonymously to the public project:

run = neptune.init_run(
    api_token=neptune.ANONYMOUS_API_TOKEN,
    project="common/fbprophet-integration",
)

You can then use the run object to track metadata with the functions listed below.

Logging Prophet summary#

create_summary()

You can log all relevant metadata at once with this function - such as forecast plots and residual diagnostics.

Parameters

Parameter         Description
model Fitted Prophet model object.
df (optional) The dataset that was used for making the forecast. If provided, additional plots will be recorded.
fcst (optional) Forecast returned by Prophet. If not provided, it'll be calculated using the df data.
log_charts Additionally save the diagnostic plots. Defaults to True.
log_interactive Save the plots as interactive HTML files. Requires the Plotly library. Defaults to True.

Returns

Dictionary with all the plots.

Example

import pandas as pd
from prophet import Prophet
import neptune.new as neptune
import neptune.new.integrations.prophet as npt_utils

run = neptune.init_run()

dataset = pd.read_csv(
    "https://raw.githubusercontent.com/facebook/prophet/main/examples/example_wp_log_peyton_manning.csv"
)
model = Prophet()
model.fit(dataset)

run["prophet_summary"] = npt_utils.create_summary(model, dataset)

Getting the model configuration#

get_model_config()

Extracts the configuration from the Prophet model object.

Parameters

Parameter Description
model Fitted Prophet model object.

Returns

Dictionary with all summary items.

Example

import pandas as pd
from prophet import Prophet
import neptune.new as neptune
import neptune.new.integrations.prophet as npt_utils

run = neptune.init_run()

dataset = pd.read_csv(
    "https://raw.githubusercontent.com/facebook/prophet/main/examples/example_wp_log_peyton_manning.csv"
)
model = Prophet()
model.fit(dataset)

run["model_config"] = npt_utils.get_model_config(model)

Getting the serialized model#

get_serialized_model()

Serializes the Prophet model.

Parameters

Parameter Description
model Fitted Prophet model object.

Returns

File containing the model.

Example

import pandas as pd
from prophet import Prophet
import neptune.new as neptune
import neptune.new.integrations.prophet as npt_utils

run = neptune.init_run()

dataset = pd.read_csv(
    "https://raw.githubusercontent.com/facebook/prophet/main/examples/example_wp_log_peyton_manning.csv"
)
model = Prophet()
model.fit(dataset)

run["model"] = npt_utils.get_serialized_model(model)

Getting forecast components#

get_forecast_components()

Get the Prophet forecast components to be saved to Neptune.

Parameters

Parameter Description
model Fitted Prophet model object.
fcst Forecast returned by Prophet, as a pandas DataFrame.

Returns

Dictionary with all the plots.

Example

import pandas as pd
from prophet import Prophet
import neptune.new as neptune
import neptune.new.integrations.prophet as npt_utils

run = neptune.init_run()

dataset = pd.read_csv(
    "https://raw.githubusercontent.com/facebook/prophet/main/examples/example_wp_log_peyton_manning.csv"
)
model = Prophet()
model.fit(dataset)
predicted = model.predict(dataset)

run["forecast_components"] = npt_utils.get_forecast_components(model, predicted)

Logging forecast plots#

create_forecast_plots()

Log additional diagnostic plots to Neptune.

Prepares the Prophet plots to be saved to Neptune.

Parameters

Parameter Description
model Fitted Prophet model object.
fcst Forecast returned by Prophet, as a pandas DataFrame.
log_interactive Save the plots as interactive HTML files. Requires the Plotly library. Defaults to True.

Returns

Dictionary with all the plots.

Example

import pandas as pd
from prophet import Prophet
import neptune.new as neptune
import neptune.new.integrations.prophet as npt_utils

run = neptune.init_run()

dataset = pd.read_csv(
    "https://raw.githubusercontent.com/facebook/prophet/main/examples/example_wp_log_peyton_manning.csv"
)
model = Prophet()
model.fit(dataset)
predicted = model.predict(dataset)

run["forecast_plots"] = npt_utils.create_forecast_plots(model, predicted)

Logging residual forecast plots#

create_residual_diagnostics_plots()

Logs additional diagnostic plots to Neptune.

Parameters

Parameter Description
alpha Transparency level of the plots. Defaults to 0.7.
fcst Forecast returned by Prophet, as a pandas DataFrame.
log_interactive Save the plots as interactive HTML files. Requires the Plotly library. Defaults to True.
y True values that were predicted, as a pandas Series.

Returns

Dictionary with all the plots.

Example

import pandas as pd
from prophet import Prophet
import neptune.new as neptune
import neptune.new.integrations.prophet as npt_utils

run = neptune.init_run()

dataset = pd.read_csv(
    "https://raw.githubusercontent.com/facebook/prophet/main/examples/example_wp_log_peyton_manning.csv"
)
model = Prophet()
model.fit(dataset)
predicted = model.predict(dataset)

run["residual_diagnostics_plot"] = npt_utils.create_residual_diagnostics_plots(
    predicted, dataset.y
)
Back to top