Core Module Documentation

neuralprophet.utils.create_event_names_for_offsets(event_name, offset)

Create names for offsets of every event

Parameters
  • event_name (string) – Name of the event

  • offset (int) – Offset of the event

Returns

Name created for the offset of the event

Return type

string

neuralprophet.utils.events_config_to_model_dims(events_config, country_holidays_config)
Convert 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

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

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

Return type

pd.DataFrame

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) – Dataframe from which datestamps will be retrieved from

Returns

All possible holiday names of given country

Return type

set

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_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

Return type

scalar

neuralprophet.utils.reg_func_regressors(regressors_config, model)

Regularization of regressors coefficients to induce sparsity

Parameters
  • regressors_config (OrderedDict) – 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.regressors_config_to_model_dims(regressors_config)

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

Parameters

regressors_config (OrderedDict) – Configurations for user specified regressors

Returns

Input dims for TimeNet model.

Note

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

Return type

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 (configure.AllSeason) – NeuralProphet seasonal model configuration

Returns

Input dims for TimeNet model

Return type

dict(int)

neuralprophet.utils.set_auto_seasonalities(df, season_config)

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 (Dataframe) – Dataframe from which datestamps will be retrieved from

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