Core Module Documentation

neuralprophet.utils.create_event_names_for_offsets(event_name, offset)

Create names for offsets of every event :param event_name: Name of the event :type event_name: string :param offset: Offset of the event :type offset: int

Returns

A name created for the offset of the event

Return type

offset_name (string)

neuralprophet.utils.events_config_to_model_dims(events_config, country_holidays_config)
Convert the NeuralProphet user specified events configurations along with country specific

holidays to input dims for TimeNet model.

Parameters
  • events_config (OrderedDict) – Configurations (upper, lower windows, regularization) for user specified events

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

Returns

A dictionary with keys corresponding to individual holidays

containing configs with properties such as the mode, list of event delims of the event corresponding to the offsets, and the indices in the input dataframe corresponding to each event.

Return type

events_dims (OrderedDict)

neuralprophet.utils.fcst_df_to_last_forecast(fcst, n_last=1)

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

Parameters
  • fcst (pd.DataFrame) – forecast df

  • n_last (int) – number of last forecasts to include

Returns

df where yhat1 is last forecast, yhat2 second to last etc

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

Return all possible holiday names of given country

Parameters
  • country (string) – country name to retrieve country specific holidays

  • df (Dataframe or list of dataframes) – Dataframe or list of dataframes from which datestamps will be

  • from (retrieved) –

Returns

A set of all possible holiday names of given country

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, scalar

neuralprophet.utils.reg_func_events(events_config, country_holidays_config, model)

Regularization of events coefficients to induce sparcity

Parameters
  • events_config (OrderedDict) – Configurations (upper, lower windows, regularization) for user specified events

  • country_holidays_config (OrderedDict) – Configurations (holiday_names, upper, lower windows, regularization) for country specific holidays

  • model (TimeNet) – The TimeNet model object

Returns

regularization loss, scalar

neuralprophet.utils.reg_func_regressors(regressors_config, model)

Regularization of regressors coefficients to induce sparcity :param regressors_config: Configurations for user specified regressors :type regressors_config: OrderedDict :param model: The TimeNet model object :type model: TimeNet

Returns

regularization loss, 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, scalar

neuralprophet.utils.regressors_config_to_model_dims(regressors_config)

Convert the NeuralProphet user specified regressors configurations to input dims for TimeNet model. :param regressors_config: Configurations for user specified regressors :type regressors_config: OrderedDict

Returns

A dictionary with keys corresponding to individual regressors

and values in a dict containing the mode, and the indices in the input dataframe corresponding to each regressor.

Return type

regressors_dims (OrderedDict)

neuralprophet.utils.season_config_to_model_dims(season_config)

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

Parameters

season_config (AllSeasonConfig) – NeuralProphet seasonal model configuration

Returns

input dims for TimeNet model

Return type

seasonal_dims (dict(int))

neuralprophet.utils.set_auto_seasonalities(df, season_config, local_modeling=False)

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

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 (Dataframe or list of dataframes) – Dataframe or list of dataframes from which datestamps will be

  • from (retrieved) –

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

  • local_modeling (bool) – when set to true each episode from list of dataframes will be considered

  • locally (i.e. seasonality, data_params, normalization) –

Returns

processed NeuralProphet seasonal model configuration

Return type

season_config (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.

Note: 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) –

Returns

ax

neuralprophet.utils.symmetric_total_percentage_error(values, estimates)

Compute STPE

Parameters
  • values (np.array) –

  • estimates (np.array) –

Returns

scalar (float)