FourierTransform

class FourierTransform(period: float, order: Optional[int] = None, mods: Optional[Sequence[int]] = None, out_column: Optional[str] = None)[source]

Bases: etna.transforms.base.Transform, etna.transforms.base.FutureMixin

Adds fourier features to the dataset.

Notes

To understand how transform works we recommend: Fourier series.

  • Parameter period is responsible for the seasonality we want to capture.

  • Parameters order and mods define which harmonics will be used.

Parameter order is a more user-friendly version of mods. For example, order=2 can be represented as mods=[1, 2, 3, 4] if period > 4 and as mods=[1, 2, 3] if 3 <= period <= 4.

Create instance of FourierTransform.

Parameters
  • period (float) –

    the period of the seasonality to capture in frequency units of time series;

    period should be >= 2

  • order (Optional[int]) –

    upper order of Fourier components to include;

    order should be >= 1 and <= ceil(period/2))

  • mods (Optional[Sequence[int]]) –

    alternative and precise way of defining which harmonics will be used, for example mods=[1, 3, 4] means that sin of the first order and sin and cos of the second order will be used;

    mods should be >= 1 and < period

  • out_column (Optional[str]) –

    • if set, name of added column, the final name will be ‘{out_columnt}_{mod}’;

    • if don’t set, name will be transform.__repr__(), repr will be made for transform that creates exactly this column

Raises
  • ValueError: – if period < 2

  • ValueError: – if both or none of order, mods is set

  • ValueError: – if order is < 1 or > ceil(period/2)

  • ValueError: – if at least one mod is < 1 or >= period

Inherited-members

Methods

fit(df)

Fit method does nothing and is kept for compatibility.

fit_transform(df)

May be reimplemented.

inverse_transform(df)

Inverse transforms dataframe.

transform(df)

Add harmonics to the dataset.

fit(df: pandas.core.frame.DataFrame) etna.transforms.timestamp.fourier.FourierTransform[source]

Fit method does nothing and is kept for compatibility.

Parameters

df (pandas.core.frame.DataFrame) – dataframe with data.

Returns

result

Return type

FourierTransform

transform(df: pandas.core.frame.DataFrame) pandas.core.frame.DataFrame[source]

Add harmonics to the dataset.

Parameters

df (pandas.core.frame.DataFrame) – dataframe with data to transform.

Returns

result – transformed dataframe

Return type

pd.Dataframe