Core Module Documentation#
- class neuralprophet.torch_prophet.TorchProphet(growth='linear', changepoints=None, n_changepoints=25, changepoint_range=0.8, yearly_seasonality='auto', weekly_seasonality='auto', daily_seasonality='auto', holidays=None, seasonality_mode='additive', seasonality_prior_scale=None, holidays_prior_scale=None, changepoint_prior_scale=None, mcmc_samples=None, interval_width=0.8, uncertainty_samples=None, stan_backend=None, **kwargs)#
Prophet wrapper for the NeuralProphet forecaster.
- Parameters
growth (String 'linear' or 'flat' to specify a linear or) – flat trend. Note: ‘flat’ is equivalent to ‘off’ in NeuralProphet.
changepoints (List of dates at which to include potential changepoints. If) – not specified, potential changepoints are selected automatically.
n_changepoints (Number of potential changepoints to include. Not used) – if input changepoints is supplied. If changepoints is not supplied, then n_changepoints potential changepoints are selected uniformly from the first changepoint_range proportion of the history.
changepoint_range (Proportion of history in which trend changepoints will) – be estimated. Defaults to 0.8 for the first 80%. Not used if changepoints is specified.
yearly_seasonality (Fit yearly seasonality.) – Can be ‘auto’, True, False, or a number of Fourier terms to generate.
weekly_seasonality (Fit weekly seasonality.) – Can be ‘auto’, True, False, or a number of Fourier terms to generate.
daily_seasonality (Fit daily seasonality.) – Can be ‘auto’, True, False, or a number of Fourier terms to generate.
holidays (pd.DataFrame with columns holiday (string) and ds (date type)) – and optionally columns lower_window and upper_window which specify a range of days around the date to be included as holidays. lower_window=-2 will include 2 days prior to the date as holidays. Also optionally can have a column prior_scale specifying the prior scale for that holiday.
seasonality_mode ('additive' (default) or 'multiplicative'.) –
seasonality_prior_scale (Not supported for regularisation in NeuralProphet,) – please use the seasonality_reg arg instead.
holidays_prior_scale (Not supported for regularisation in NeuralProphet.) –
changepoint_prior_scale (Not supported for regularisation in NeuralProphet,) – please use the trend_reg arg instead.
mcmc_samples (Not required for NeuralProphet) –
interval_width (Float, width of the uncertainty intervals provided) – for the forecast. Converted to list of quantiles for NeuralProphet. Use the quantiles arg to pass quantiles directly to NeuralProphet.
uncertainty_samples (Not required for NeuralProphet.) –
stan_backend (Not supported by NeuralProphet.) –
- add_country_holidays(country_name, **kwargs)#
Add in built-in holidays for the specified country.
These holidays will be included in addition to any specified on model initialization.
Holidays will be calculated for arbitrary date ranges in the history and future. See the online documentation for the list of countries with built-in holidays.
Built-in country holidays can only be set for a single country.
- Parameters
country_name (Name of the country, like 'UnitedStates' or 'US') –
- Return type
The NeuralProphet object.
- add_regressor(name, prior_scale=None, standardize='auto', mode='additive', **kwargs)#
Add an additional (future) regressor to be used for fitting and predicting.
- Parameters
name (string name of the regressor.) –
prior_scale (Not supported in NeuralProphet.) –
standardize (optional, specify whether this regressor will be) – standardized prior to fitting. Can be ‘auto’ (standardize if not binary), True, or False.
mode (optional, 'additive' or 'multiplicative'. Defaults to) – self.seasonality_mode. Not supported in NeuralProphet.
- Return type
The NeuralProphet object.
- add_seasonality(name, period, fourier_order, prior_scale=None, mode=None, condition_name=None, **kwargs)#
Add a seasonal component with specified period, number of Fourier components, and prior scale.
Increasing the number of Fourier components allows the seasonality to change more quickly (at risk of overfitting). Default values for yearly and weekly seasonalities are 10 and 3 respectively.
Increasing prior scale will allow this seasonality component more flexibility, decreasing will dampen it. If not provided, will use the seasonality_prior_scale provided on initialization (defaults to 10).
Mode can be specified as either ‘additive’ or ‘multiplicative’. If not specified, self.seasonality_mode will be used (defaults to additive). Additive means the seasonality will be added to the trend, multiplicative means it will multiply the trend.
If condition_name is provided, the dataframe passed to fit and predict should have a column with the specified condition_name containing booleans which decides when to apply seasonality.
- Parameters
name (string name of the seasonality component.) –
period (float number of days in one period.) –
fourier_order (int number of Fourier components to use.) –
prior_scale (Not supported in NeuralProphet.) –
mode (optional 'additive' or 'multiplicative') –
condition_name (Not supported in NeuralProphet.) –
- Return type
The NeuralProphet object.
- fit(df, **kwargs)#
Fit the NeuralProphet model.
This sets self.params to contain the fitted model parameters. It is a dictionary parameter names as keys and the following items:
k (Mx1 array): M posterior samples of the initial slope. m (Mx1 array): The initial intercept. delta (MxN array): The slope change at each of N changepoints. beta (MxK matrix): Coefficients for K seasonality features. sigma_obs (Mx1 array): Noise level.
Note that M=1 if MAP estimation.
- Parameters
df (pd.DataFrame containing the history. Must have columns ds (date) – type) and y, the time series. If self.growth is ‘logistic’, then df must also have a column cap that specifies the capacity at each ds.
kwargs (Additional arguments passed to the optimizing or sampling) – functions in Stan.
- Return type
The fitted NeuralProphet object.
- make_future_dataframe(periods, freq='D', include_history=True, **kwargs)#
Simulate the trend using the extrapolated generative model.
- Parameters
periods (Int number of periods to forecast forward.) –
freq (Any valid frequency for pd.date_range, such as 'D' or 'M'.) –
include_history (Boolean to include the historical dates in the data) – frame for predictions.
- Returns
pd.Dataframe that extends forward from the end of self.history for the
requested number of periods.
- plot(fcst, ax=None, uncertainty=True, plot_cap=True, xlabel='ds', ylabel='y', figsize=(10, 6), include_legend=False, **kwargs)#
Plot the NeuralProphet forecast.
- Parameters
fcst (pd.DataFrame output of self.predict.) –
ax (Optional matplotlib axes on which to plot.) –
uncertainty (Not supported in NeuralProphet.) –
plot_cap (Not supported in NeuralProphet.) –
xlabel (Optional label name on X-axis) –
ylabel (Optional label name on Y-axis) –
figsize (Optional tuple width, height in inches.) –
include_legend (Not supported in NeuralProphet.) –
- Return type
A matplotlib figure.
- plot_components(fcst, uncertainty=True, plot_cap=True, weekly_start=0, yearly_start=0, figsize=None, **kwargs)#
Plot the NeuralProphet forecast components.
Will plot whichever are available of: trend, holidays, weekly seasonality, and yearly seasonality.
- Parameters
fcst (pd.DataFrame output of self.predict.) –
uncertainty (Not supported in NeuralProphet.) –
plot_cap (Not supported in NeuralProphet.) –
weekly_start (Not supported in NeuralProphet.) –
yearly_start (Not supported in NeuralProphet.) –
figsize (Optional tuple width, height in inches.) –
- Return type
A matplotlib figure.
- predict(df=None, **kwargs)#
Predict using the NeuralProphet model.
- Parameters
df (pd.DataFrame with dates for predictions (column ds), and capacity) – (column cap) if logistic growth. If not provided, predictions are made on the history.
- Return type
A pd.DataFrame with the forecast components.
- predict_trend(df)#
Predict trend using the NeuralProphet model.
- Parameters
df (Prediction dataframe.) –
- Return type
Vector with trend on prediction dates.
- setup_dataframe(df, initialize_scales=False)#
Dummy function that raises an error.
This function is not supported in NeuralProphet.
- validate_column_name(name, check_holidays=True, check_seasonalities=True, check_regressors=True)#
Validates the name of a seasonality, holiday, or regressor.
- Parameters
name (string) –
check_holidays (bool check if name already used for holiday) –
check_seasonalities (bool check if name already used for seasonality) –
check_regressors (bool check if name already used for regressor) –
- validate_inputs()#
Validates the inputs to NeuralProphet.
- neuralprophet.torch_prophet.plot(self, fcst, ax=None, uncertainty=True, plot_cap=True, xlabel='ds', ylabel='y', figsize=(10, 6), include_legend=False, **kwargs)#
Plot the NeuralProphet forecast.
- Parameters
fcst (pd.DataFrame output of self.predict.) –
ax (Optional matplotlib axes on which to plot.) –
uncertainty (Not supported in NeuralProphet.) –
plot_cap (Not supported in NeuralProphet.) –
xlabel (Optional label name on X-axis) –
ylabel (Optional label name on Y-axis) –
figsize (Optional tuple width, height in inches.) –
include_legend (Not supported in NeuralProphet.) –
- Return type
A matplotlib figure.
- neuralprophet.torch_prophet.plot_components(m, fcst, uncertainty=True, plot_cap=True, weekly_start=0, yearly_start=0, figsize=None, **kwargs)#
Plot the NeuralProphet forecast components.
Will plot whichever are available of: trend, holidays, weekly seasonality, yearly seasonality, and additive and multiplicative extra regressors.
- Parameters
m (NeuralProphet model.) –
fcst (pd.DataFrame output of m.predict.) –
uncertainty (Not supported in NeuralProphet.) –
plot_cap (Not supported in NeuralProphet.) –
weekly_start (Not supported in NeuralProphet.) –
yearly_start (Not supported in NeuralProphet.) –
figsize (Optional tuple width, height in inches.) –
- Return type
A matplotlib figure.
- neuralprophet.torch_prophet.plot_components_plotly(m, fcst, uncertainty=True, plot_cap=True, figsize=(900, 200), **kwargs)#
Plot the NeuralProphet forecast components using Plotly. See plot_plotly() for Plotly setup instructions
Will plot whichever are available of: trend, holidays, weekly seasonality, yearly seasonality, and additive and multiplicative extra regressors.
- Parameters
m (NeuralProphet model.) –
fcst (pd.DataFrame output of m.predict.) –
uncertainty (Not supported in NeuralProphet.) –
plot_cap (Not supported in NeuralProphet.) –
figsize (Not supported in NeuralProphet.) –
- Return type
A Plotly Figure.
- neuralprophet.torch_prophet.plot_plotly(self, fcst, ax=None, uncertainty=True, plot_cap=True, xlabel='ds', ylabel='y', figsize=(10, 6), include_legend=False, **kwargs)#
Plot the NeuralProphet forecast.
- Parameters
fcst (pd.DataFrame output of self.predict.) –
ax (Optional matplotlib axes on which to plot.) –
uncertainty (Not supported in NeuralProphet.) –
plot_cap (Not supported in NeuralProphet.) –
xlabel (Optional label name on X-axis) –
ylabel (Optional label name on Y-axis) –
figsize (Optional tuple width, height in inches.) –
include_legend (Not supported in NeuralProphet.) –
- Return type
A matplotlib figure.