Core Module Documentation#

class neuralprophet.time_dataset.GlobalTimeDataset(df, **kwargs)#
class neuralprophet.time_dataset.TimeDataset(df, name, **kwargs)#

Create a PyTorch dataset of a tabularized time-series

drop_nan_after_init(df, predict_steps, drop_missing)#

Checks if inputs/targets contain any NaN values and drops them, if user opts to. :param drop_missing: whether to automatically drop missing samples from the data :type drop_missing: bool :param predict_steps: number of steps to predict :type predict_steps: int

filter_samples_after_init(prediction_frequency=None)#

Filters samples from the dataset based on the forecast frequency. :param prediction_frequency: periodic interval in which forecasts should be made. :type prediction_frequency: int :param Note: :param —-: :param E.g. if prediction_frequency=7: :param forecasts are only made on every 7th step (once in a week in case of daily: :param resolution).:

init_after_tabularized(inputs, targets=None)#

Create Timedataset with data. :param inputs: Identical to returns from tabularize_univariate_datetime() :type inputs: ordered dict :param targets: Identical to returns from tabularize_univariate_datetime() :type targets: np.array, float

neuralprophet.time_dataset.fourier_series(dates, period, series_order)#

Provides Fourier series components with the specified frequency and order. .. note:: Identical to OG Prophet.

Parameters
  • dates (pd.Series) – Containing timestamps

  • period (float) – Number of days of the period

  • series_order (int) – Number of fourier components

Returns

Matrix with seasonality features

Return type

np.array

neuralprophet.time_dataset.fourier_series_t(t, period, series_order)#

Provides Fourier series components with the specified frequency and order. .. note:: This function is identical to Meta AI’s Prophet Library

Parameters
  • t (pd.Series, float) – Containing time as floating point number of days

  • period (float) – Number of days of the period

  • series_order (int) – Number of fourier components

Returns

Matrix with seasonality features

Return type

np.array

neuralprophet.time_dataset.make_country_specific_holidays_df(year_list, country)#

Make dataframe of country specific holidays for given years and countries :param year_list: List of years :type year_list: list :param country: List of country names :type country: str, list

Returns

Containing country specific holidays df with columns ‘ds’ and ‘holiday’

Return type

pd.DataFrame

neuralprophet.time_dataset.make_events_features(df, config_events: Optional[OrderedDict[str, neuralprophet.configure.Event]] = None, config_country_holidays=None)#

Construct arrays of all event features :param df: Dataframe with all values including the user specified events (provided by user) :type df: pd.DataFrame :param config_events: User specified events, each with their upper, lower windows (int), regularization :type config_events: configure.ConfigEvents :param config_country_holidays: Configurations (holiday_names, upper, lower windows, regularization) for country specific holidays :type config_country_holidays: configure.ConfigCountryHolidays

Returns

  • np.array – All additive event features (both user specified and country specific)

  • np.array – All multiplicative event features (both user specified and country specific)

neuralprophet.time_dataset.make_regressors_features(df, config_regressors)#

Construct arrays of all scalar regressor features :param df: Dataframe with all values including the user specified regressors :type df: pd.DataFrame :param config_regressors: User specified regressors config :type config_regressors: configure.ConfigFutureRegressors

Returns

  • np.array – All additive regressor features

  • np.array – All multiplicative regressor features

neuralprophet.time_dataset.seasonal_features_from_dates(df, config_seasonality: neuralprophet.configure.ConfigSeasonality)#

Dataframe with seasonality features. Includes seasonality features, holiday features, and added regressors. :param df: Dataframe with all values :type df: pd.DataFrame :param config_seasonality: Configuration for seasonalities :type config_seasonality: configure.ConfigSeasonality

Returns

Dictionary with keys for each period name containing an np.array with the respective regression features. each with dims: (len(dates), 2*fourier_order)

Return type

OrderedDict

neuralprophet.time_dataset.tabularize_univariate_datetime(df, predict_mode=False, n_lags=0, n_forecasts=1, predict_steps=1, config_seasonality: Optional[neuralprophet.configure.ConfigSeasonality] = None, config_events: Optional[OrderedDict[str, neuralprophet.configure.Event]] = None, config_country_holidays=None, config_lagged_regressors: Optional[OrderedDict[str, neuralprophet.configure.LaggedRegressor]] = None, config_regressors: Optional[neuralprophet.configure.ConfigFutureRegressors] = None, config_missing=None, prediction_frequency=None)#

Create a tabular dataset from univariate timeseries for supervised forecasting. .. note:

Data must have no gaps.
If data contains missing values, they are ignored for the creation of the dataset.
Parameters
  • df (pd.DataFrame) – Sequence of observations with original ds, y and normalized t, y_scaled columns

  • config_seasonality (configure.ConfigSeasonality) – Configuration for seasonalities

  • n_lags (int) – Number of lagged values of series to include as model inputs (aka AR-order)

  • n_forecasts (int) – Number of steps to forecast into future

  • config_events (configure.ConfigEvents) – User specified events, each with their upper, lower windows (int) and regularization

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

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

  • config_regressors (configure.ConfigFutureRegressors) – Configuration for regressors

  • predict_mode (bool) –

    Chooses the prediction mode Options

    • (default) False: Includes target values

    • True: Does not include targets but includes entire dataset as input

Returns

  • OrderedDict – Model inputs, each of len(df) but with varying dimensions .. note:

    Contains the following data:
    Model Inputs
        * ``time`` (np.array, float), dims: (num_samples, 1)
        * ``seasonalities`` (OrderedDict), named seasonalities
        each with features (np.array, float) - dims: (num_samples, n_features[name])
        * ``lags`` (np.array, float), dims: (num_samples, n_lags)
        * ``covariates`` (OrderedDict), named covariates,
        each with features (np.array, float) of dims: (num_samples, n_lags)
        * ``events`` (OrderedDict), events,
        each with features (np.array, float) of dims: (num_samples, n_lags)
        * ``regressors`` (OrderedDict), regressors,
        each with features (np.array, float) of dims: (num_samples, n_lags)
    
  • np.array, float – Targets to be predicted of same length as each of the model inputs, dims: (num_samples, n_forecasts)