pmdarima.preprocessing.DateFeaturizer

class pmdarima.preprocessing.DateFeaturizer(column_name, with_day_of_week=True, with_day_of_month=True, prefix=None)[source][source]

Create exogenous date features

Given an exogenous feature of dtype TimeStamp, creates a set of dummy and ordinal variables indicating:

  • Day of the week

    Particular days of the week may align with quasi-seasonal trends.

  • Day of the month

    Useful for modeling things like the end-of-month effect, ie., a department spends the remainder of its monthly budget to avoid future budget cuts, and the last Friday of the month is heavy on spending.

The motivation for this featurizer comes from a blog post by Rob Hyndman [1] on modeling quasi-seasonal patterns in time series. Note that an exogenous array _must_ be provided at inference.

Parameters:

column_name : str

The name of the date column. This forces the exogenous array to be a Pandas DataFrame, and does not permit a np.ndarray as others may.

with_day_of_week : bool, optional (default=True)

Whether to include dummy variables for the day of the week (in {0, 1}).

with_day_of_month : bool, optional (default=True)

Whether to include an ordinal feature for the day of the month (1-31).

prefix : str or None, optional (default=None)

The feature prefix

Notes

  • In order to use time series with holes, it is required that an X array be provided at prediction time. Other featurizers automatically create exog arrays into the future for inference, but this is not possible currently with the date featurizer. Your code must provide the dates for which you are forecasting as exog features.

  • The column_name field is dropped in the transformed exogenous array.

References

Examples

>>> from pmdarima.datasets._base import load_date_example
>>> y, X = load_date_example()
>>> feat = DateFeaturizer(column_name='date')
>>> _, X_prime = feat.fit_transform(y, X)
>>> X_prime.head()
   DATE-WEEKDAY-0  DATE-WEEKDAY-1  ...  DATE-WEEKDAY-6  DATE-DAY-OF-MONTH
0               0               1  ...               0                  1
1               0               0  ...               0                  2
2               0               0  ...               0                  3
3               0               0  ...               0                  4
4               0               0  ...               0                  5

Methods

fit(y[, X])

Fit the transformer

fit_transform(y[, X])

Fit and transform the arrays

get_metadata_routing()

Get metadata routing of this object.

get_params([deep])

Get parameters for this estimator.

set_output(*[, transform])

Set output container.

set_params(**params)

Set the parameters of this estimator.

set_transform_request(*[, n_periods])

Request metadata passed to the transform method.

transform(y[, X])

Create date features

__init__(column_name, with_day_of_week=True, with_day_of_month=True, prefix=None)[source][source]

Examples using pmdarima.preprocessing.DateFeaturizer

Modeling quasi-seasonal trends with date features

Modeling quasi-seasonal trends with date features