FourierFeatureTransformer¶
yohou.preprocessing.time_features.FourierFeatureTransformer
¶
Bases: BaseTransformer
Generate Fourier harmonic features from the time column.
Creates sin/cos feature pairs at specified harmonics of a given
seasonal period, useful for encoding cyclical patterns as inputs
to reduction forecasters. Output columns are prefixed with
fourier_.
For each harmonic \(k\) and seasonal period \(S\), the features at time step \(t\) are:
where \(t\) is the number of time steps since the first observed
timestamp, \(S\) is the seasonality parameter, and \(k\) ranges
over the selected harmonics. Harmonics must satisfy
\(k \leq S / 2\) (Nyquist limit).
Parameters¶
| Name | Type | Description | Default |
|---|---|---|---|
seasonality
|
float
|
Seasonal period length in number of time steps. Can be
non-integer (e.g., |
7.0
|
harmonics
|
list of int or None
|
Which Fourier harmonics to include. For example,
|
None
|
Attributes¶
| Name | Type | Description |
|---|---|---|
harmonics_ |
list of int
|
Effective list of harmonics used for feature generation. |
first_time_ |
datetime
|
First observed timestamp, used as reference for index computation. |
See Also¶
CalendarFeatureTransformer: Calendar features (month, day of week, etc.).HolidayFeatureTransformer: Binary holiday indicator.TimeIndexTransformer: Numeric time index for trend features.FourierSeasonalityForecaster: Forecaster-level Fourier seasonality.
Examples¶
>>> import polars as pl
>>> from datetime import datetime
>>> time = pl.datetime_range(
... start=datetime(2020, 1, 1), end=datetime(2020, 1, 15), interval="1d", eager=True
... )
>>> X = pl.DataFrame({"time": time, "value": range(len(time))})
>>> transformer = FourierFeatureTransformer(seasonality=7.0, harmonics=[1, 2])
>>> transformer.fit(X)
FourierFeatureTransformer(harmonics=[1, 2])
>>> X_t = transformer.transform(X)
>>> "fourier_7.0_sin_1" in X_t.columns
True
Source Code¶
Show/Hide source
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 | |
Methods¶
get_feature_names_out(input_features=None)
¶
Get output feature names for transformation.
Parameters¶
| Name | Type | Description | Default |
|---|---|---|---|
input_features
|
array-like of str or None
|
Input feature names (unused, for API compatibility). |
None
|
Returns¶
| Type | Description |
|---|---|
list of str
|
Generated Fourier feature column names. |
Source Code¶
Show/Hide source
Tutorials¶
The following example notebooks use this component:
-
How to Add Calendar, Fourier, and Holiday Features
Data-Features
Enrich your feature matrix with time-derived signals using CalendarFeatureTransformer, FourierFeatureTransformer, and HolidayFeatureTransformer.