Core Module Documentation#

neuralprophet.utils.config_events_to_model_dims(config_events, config_country_holidays)#
Convert user specified events configurations along with country specific

holidays to input dims for TimeNet model.

Parameters:
  • config_events (configure.ConfigEvents) – Configurations (upper, lower windows, regularization) for user specified events

  • config_country_holidays (configure.ConfigCountryHolidays) – Configurations (holiday_names, upper, lower windows, regularization) for country specific holidays

Returns:

input dims for TimeNet model

Note

This dictionaries’ keys correspond to individual holidays and contains configs such as the mode, list of event delims of the event corresponding to the offsets and indices in the input dataframe corresponding to each event.

Return type:

OrderedDict

neuralprophet.utils.config_regressors_to_model_dims(config_regressors)#

Convert the NeuralProphet user specified regressors configurations to input dims for TimeNet model.

Parameters:

config_regressors (configure.ConfigFutureRegressors) – Configurations for user specified regressors

Returns:

Input dims for TimeNet model.

Note

This dictionaries’ keys correspond to individual regressor and values in a dict containing the mode and the indices in the input dataframe corresponding to each regressor.

Return type:

OrderedDict

neuralprophet.utils.config_season_to_model_dims(config_season)#

Convert the NeuralProphet seasonal model configuration to input dims for TimeNet model.

Parameters:

config_season (configure.AllSeason) – NeuralProphet seasonal model configuration

Returns:

Input dims for TimeNet model

Return type:

dict(int)

neuralprophet.utils.create_event_names_for_offsets(event_name, offset)#

Create names for offsets of every event

Parameters:
  • event_name (str) – Name of the event

  • offset (int) – Offset of the event

Returns:

Name created for the offset of the event

Return type:

str

neuralprophet.utils.fcst_df_to_latest_forecast(fcst, quantiles, n_last=1)#

Converts from line-per-lag to line-per-forecast.

Parameters:
  • fcst (pd.DataFrame) – Forecast df

  • quantiles (list, default None) – A list of float values between (0, 1) which indicate the set of quantiles to be estimated.

  • n_last (int) – Number of latest forecasts to include

Returns:

Dataframe where origin-0 is latest forecast, origin-1 second to latest etc

Return type:

pd.DataFrame

neuralprophet.utils.get_holidays_from_country(country, df=None)#

Return all possible holiday names of given country

Parameters:
  • country (str) – Country name to retrieve country specific holidays

  • df (pd.Dataframe) – Dataframe from which datestamps will be retrieved from

Returns:

All possible holiday names of given country

Return type:

set

neuralprophet.utils.load(path)#

retrieve a fitted model from a .np file that was saved by save.

Parameters:

path (str) – path and filename to be saved. filename could be any but suggested to have extension .np.

Returns:

previously saved model

Return type:

np.forecaster.NeuralProphet

Examples

Saved model could be loaded from disk file test_save_model.np
>>> from neuralprophet import load
>>> model = load("test_save_model.np")
neuralprophet.utils.reg_func_abs(weights)#

Regularization of weights to induce sparcity

Parameters:

weights (torch.Tensor) – Model weights to be regularized towards zero

Returns:

Regularization loss

Return type:

torch.Tensor

neuralprophet.utils.reg_func_covariates(config_lagged_regressors: ConfigLaggedRegressors, model)#

Regularization of lagged covariates to induce sparsity

Parameters:
  • config_lagged_regressors (configure.ConfigLaggedRegressors) – Configurations for lagged regressors

  • model (TimeNet) – TimeNet model object

Returns:

Regularization loss

Return type:

scalar

neuralprophet.utils.reg_func_events(config_events, config_country_holidays, model)#

Regularization of events coefficients to induce sparcity

Parameters:
  • config_events (configure.ConfigEvents) – Configurations (upper, lower windows, regularization) for user specified events

  • config_country_holidays (configure.ConfigCountryHolidays) – Configurations (holiday_names, upper, lower windows, regularization) for country specific holidays

  • model (TimeNet) – The TimeNet model object

Returns:

Regularization loss

Return type:

scalar

neuralprophet.utils.reg_func_regressors(config_regressors, model)#

Regularization of regressors coefficients to induce sparsity

Parameters:
  • config_regressors (configure.ConfigFutureRegressors) – Configurations for user specified regressors

  • model (TimeNet) – TimeNet model object

Returns:

Regularization loss

Return type:

scalar

neuralprophet.utils.reg_func_trend(weights, threshold=None)#

Regularization of weights to induce sparcity

Parameters:
  • weights (torch.Tensor) – Model weights to be regularized towards zero

  • threshold (float) – Value below which not to regularize weights

Returns:

regularization loss

Return type:

torch.Tensor

neuralprophet.utils.save(model, path)#

save a fitted np model to a disk file.

Parameters:
  • model (np.forecaster.NeuralProphet) – input model that is fitted

  • path (str) – path and filename to be saved. filename could be any but suggested to have extension .np.

Examples

After you fitted a model, you may save the model to save_test_model.np
>>> from neuralprophet import save
>>> save(model, "test_save_model.np")
neuralprophet.utils.set_auto_seasonalities(df, config_season)#

Set seasonalities that were left on auto or set by user.

Note

Turns on yearly seasonality if there is >=2 years of history.

Turns on weekly seasonality if there is >=2 weeks of history, and the spacing between dates in the history is <7 days.

Turns on daily seasonality if there is >=2 days of history, and the spacing between dates in the history is <1 day.

Parameters:
  • df (pd.Dataframe) – Dataframe from which datestamps will be retrieved from

  • config_season (configure.AllSeason) – NeuralProphet seasonal model configuration, as after __init__

Returns:

Processed NeuralProphet seasonal model configuration

Return type:

configure.AllSeason

neuralprophet.utils.set_log_level(log_level='INFO', include_handlers=False)#

Set the log level of all logger objects

Parameters:
  • log_level (str) – The log level of the logger objects used for printing procedure status updates for debugging/monitoring. Should be one of NOTSET, DEBUG, INFO, WARNING, ERROR or CRITICAL

  • include_handlers (bool) – Include any specified file/stream handlers

neuralprophet.utils.set_random_seed(seed=0)#

Sets the random number generator to a fixed seed.

Parameters:

seed (numeric) – Seed value for random number generator

Note

This needs to be set each time before fitting the model.

neuralprophet.utils.set_y_as_percent(ax)#

Set y axis as percentage

Parameters:

ax (matplotlib axis) – Respective y axis element

Returns:

Manipulated axis element

Return type:

matplotlib axis

neuralprophet.utils.symmetric_total_percentage_error(values, estimates)#

Compute STPE

Parameters:
  • values (np.array) – Input values

  • estimates (np.array) – Respective estimates of input values

Returns:

Symmetric total percentage error

Return type:

float