Skip to content

API reference: Prophet integration#

You can use the functions provided by the Neptune-Prophet integration to log:

  • parameters
  • forecast data frames
  • residual diagnostic charts
  • cross-validation folds
  • other metadata

create_summary()#

Logs all relevant metadata at once, such as forecast plots and residual diagnostics.

Parameters

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

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, dataset, log_interactive=True
)
If Neptune can't find your project name or API token

As a best practice, you should save your Neptune API token and project name as environment variables:

export NEPTUNE_API_TOKEN="h0dHBzOi8aHR0cHM6Lkc78ghs74kl0jv...Yh3Kb8"
export NEPTUNE_PROJECT="ml-team/classification"

Alternatively, you can pass the information when using a function that takes api_token and project as arguments:

run = neptune.init_run(
    api_token="h0dHBzOi8aHR0cHM6Lkc78ghs74kl0jv...Yh3Kb8", # (1)!
    project="ml-team/classification", # (2)!
)
  1. In the bottom-left corner, expand the user menu and select Get my API token.
  2. You can copy the path from the project details ( Details & privacy).

If you haven't registered, you can log anonymously to a public project:

api_token=neptune.ANONYMOUS_API_TOKEN
project="common/quickstarts"

Make sure not to publish sensitive data through your code!


get_model_config()#

Extracts the configuration from the Prophet model object.

Parameters

Parameter Type Default Description
model Prophet - Fitted Prophet model object.

Returns

Dictionary with all summary items.

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["model_config"] = npt_utils.get_model_config(model)

get_serialized_model()#

Serializes the Prophet model.

Parameters

Parameter Type Default Description
model Prophet - Fitted Prophet model object.

Returns

File containing the model.

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["model"] = npt_utils.get_serialized_model(model)

get_forecast_components()#

Get the forecast components (such as trend and monthly seasonality) produced by Prophet.

Parameters

Parameter Type Default Description
model Prophet - Fitted Prophet model object.
fcst pandas.DataFrame - Forecast returned by Prophet.

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)
predicted = model.predict(dataset)

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

create_forecast_plots()#

Prepares the Prophet plots (forecast components, changepoints, forecast with prediction interval) to be saved to Neptune.

Parameters

Parameter     Type        Default Description
model Prophet - Fitted Prophet model object.
fcst pandas.DataFrame None Forecast returned by Prophet.
log_interactive bool, optional False Save the plots as interactive HTML files. Requires the Plotly library.

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)
predicted = model.predict(dataset)

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

create_residual_diagnostics_plots()#

Prepares the additional diagnostic plots (such as histogram of residuals, ACF plot, QQ-plot for residuals) to be saved to Neptune.

Parameters

Parameter     Type        Default Description
fcst pandas.DataFrame - Forecast returned by Prophet.
y pandas.Series - True values that were predicted.
log_interactive bool, optional False Save the plots as interactive HTML files. Requires the Plotly library.
alpha float, optional 0.7 Transparency level of the plots.

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)
predicted = model.predict(dataset)

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

See also

neptune-prophet on GitHub