Prophet integration guide#
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 
Before you start#
- Sign up at neptune.ai/register.
- Create a project for storing your metadata.
- Have Prophet installed.
- (optional) To log the plots as interactive HTML visualizations, you need to have the Plotly graphing library installed.
- You can enable logging as interactive HTML by setting the
log_interactive
parameter toTrue
where applicable. - Otherwise, the plots are recorded as static images by default.
- You can enable logging as interactive HTML by setting the
Installing the integration#
To use your pre-installed version of Neptune together with the integration:
To install both Neptune and the integration:
Passing your Neptune credentials
Once you've registered and created a project, set your Neptune API token and full project name to the NEPTUNE_API_TOKEN
and NEPTUNE_PROJECT
environment variables, respectively.
To find your API token: In the bottom-left corner of the Neptune app, expand the user menu and select Get my API token.
To find your project: Your full project name has the form workspace-name/project-name
. To copy the name, click the menu in the top-right corner and select Properties.
While it's not recommended especially for the API token, you can also pass your credentials in the code when initializing Neptune.
run = neptune.init_run(
project="ml-team/classification", # your full project name here
api_token="h0dHBzOi8aHR0cHM6Lkc78ghs74kl0jvYh...3Kb8", # your API token here
)
For more help, see Setting Neptune credentials.
If you'd rather follow the guide without any setup, you can run the example in Colab .
Logging options#
In order to track the metadata to Neptune, you need to initialize a Neptune run.
Haven't registered?
If you haven't registered or set up your credentials, you can log anonymously to the public project:
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 False . |
Returns
Dictionary with all the plots.
Example
import pandas as pd
from prophet import Prophet
import neptune
import neptune.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=model, df=dataset, log_interactive=True
)
Getting the model configuration#
To extract the configuration from the Prophet model object, use the get_model_config()
function:
run = neptune.init_run()
dataset = ...
model = Prophet()
model.fit(dataset)
run["model_config"] = npt_utils.get_model_config(model)
Getting the serialized model#
To serialize the Prophet model, you can use the get_serialized_model()
function:
run = neptune.init_run()
dataset = ...
model = Prophet()
model.fit(dataset)
run["model"] = npt_utils.get_serialized_model(model)
Getting forecast components#
To get the forecast components (such as trend and monthly seasonality) produced by Prophet, use the get_forecast_components()
function:
run = neptune.init_run()
dataset = ...
model = Prophet()
model.fit(dataset)
predicted = model.predict(dataset)
run["forecast_components"] = npt_utils.get_forecast_components(model, predicted)
Logging forecast plots#
To save Prophet plots (such as forecast components, changepoints, forecast with prediction interval), use the create_forecast_plots()
function:
model.fit(dataset)
predicted = model.predict(dataset)
run["forecast_plots"] = npt_utils.create_forecast_plots(model, predicted)
Logging residual forecast plots#
To save additional diagnostic plots (such as histogram of residuals, ACF plot, QQ-plot for residuals) to Neptune, use the create_residual_diagnostics_plots()
function:
model.fit(dataset)
predicted = model.predict(dataset)
run["residual_diagnostics_plot"] = npt_utils.create_residual_diagnostics_plots(
predicted, dataset.y
)
Related
- API reference ≫ Prophet integration
- neptune-prophet repository on GitHub
- Prophet documentation
- Prophet on GitHub