etna.transforms.HolidayTransform#
- class HolidayTransform(iso_code: str = 'RUS', mode: str = 'binary', out_column: str | None = None, in_column: str | None = None)[source]#
Bases:
IrreversibleTransform
HolidayTransform generates series that indicates holidays in given dataset.
In
binary
mode shows the presence of holiday in a given timestamp.In
category
mode shows the name of the holiday in a given timestamp, the value “NO_HOLIDAY” is reserved for days without holidays.In
days_count
mode shows the frequency of holidays in a given period.If the frequency is weekly, then we count the proportion of holidays in a week (Monday-Sunday) that contains this day.
If the frequency is monthly, then we count the proportion of holidays in a month that contains this day.
If the frequency is yearly, then we count the proportion of holidays in a year that contains this day.
Transform can accept timestamp data in two forms:
As index. In this case the dataset index is used to compute features. The features will be the same for each segment.
As external column. In this case for each segment its
in_column
will be used to compute features. Indays_count
mode it is expected that for all segments only one frequency is used.
Notes
During fitting int
days_count
mode the transform saves frequency. It is assumed to be the same duringtransform
.Create instance of HolidayTransform.
- Parameters:
iso_code (str) – internationally recognised codes, designated to country for which we want to find the holidays.
mode (str) – binary to indicate holidays, category to specify which holiday do we have at each day, days_count to determine the proportion of holidays in a given period of time.
out_column (str | None) – name of added column. Use
self.__repr__()
if not given.in_column (str | None) – name of column to work with; if not given, index is used, only datetime index is supported
Methods
fit
(ts)Fit the transform.
fit_transform
(ts)Fit and transform TSDataset.
Return the list with regressors created by the transform.
Inverse transform TSDataset.
load
(path)Load an object.
Get grid for tuning hyperparameters.
save
(path)Save the object.
set_params
(**params)Return new object instance with modified parameters.
to_dict
()Collect all information about etna object in dict.
transform
(ts)Transform TSDataset inplace.
Attributes
This class stores its
__init__
parameters as attributes.- fit(ts: TSDataset) HolidayTransform [source]#
Fit the transform.
- Parameters:
ts (TSDataset) – Dataset to fit the transform on.
- Returns:
The fitted transform instance.
- Raises:
ValueError: – if index timestamp is integer and
in_column
isn’t setValueError: – if external timestamp isn’t datetime
ValueError – if in
days_count
mode external timestamp doesn’t have frequencyValueError – if in
days_count
mode external timestamp doesn’t have the same frequency for all segments
- Return type:
- fit_transform(ts: TSDataset) TSDataset [source]#
Fit and transform TSDataset.
May be reimplemented. But it is not recommended.
- get_regressors_info() List[str] [source]#
Return the list with regressors created by the transform. :returns: List with regressors created by the transform.
- classmethod load(path: Path) Self [source]#
Load an object.
Warning
This method uses
dill
module which is not secure. It is possible to construct malicious data which will execute arbitrary code during loading. Never load data that could have come from an untrusted source, or that could have been tampered with.- Parameters:
path (Path) – Path to load object from.
- Returns:
Loaded object.
- Return type:
Self
- params_to_tune() Dict[str, BaseDistribution] [source]#
Get grid for tuning hyperparameters.
This is default implementation with empty grid.
- Returns:
Empty grid.
- Return type:
- set_params(**params: dict) Self [source]#
Return new object instance with modified parameters.
Method also allows to change parameters of nested objects within the current object. For example, it is possible to change parameters of a
model
in aPipeline
.Nested parameters are expected to be in a
<component_1>.<...>.<parameter>
form, where components are separated by a dot.- Parameters:
**params (dict) – Estimator parameters
- Returns:
New instance with changed parameters
- Return type:
Self
Examples
>>> from etna.pipeline import Pipeline >>> from etna.models import NaiveModel >>> from etna.transforms import AddConstTransform >>> model = NaiveModel(lag=1) >>> transforms = [AddConstTransform(in_column="target", value=1)] >>> pipeline = Pipeline(model, transforms=transforms, horizon=3) >>> pipeline.set_params(**{"model.lag": 3, "transforms.0.value": 2}) Pipeline(model = NaiveModel(lag = 3, ), transforms = [AddConstTransform(in_column = 'target', value = 2, inplace = True, out_column = None, )], horizon = 3, )