CalendarFeatureTransformer¶
yohou.preprocessing.calendar.CalendarFeatureTransformer
¶
Bases: BaseTransformer
Extract calendar-based features from the time column.
Creates new integer feature columns derived from the datetime index,
useful for capturing seasonal and calendar effects in reduction
forecasters. Output columns are prefixed with cal_.
Each feature is a deterministic function of the timestamp \(t\):
For example, \(f_{\text{month}}(t) \in \{1, \ldots, 12\}\) and \(f_{\text{is_weekend}}(t) \in \{0, 1\}\).
Parameters¶
| Name | Type | Description | Default |
|---|---|---|---|
features
|
list of str or None
|
Calendar features to extract. If |
None
|
Attributes¶
| Name | Type | Description |
|---|---|---|
applicable_features_ |
list of str
|
Calendar features that will be extracted during transform. |
See Also¶
HolidayFeatureTransformer: Binary holiday indicator from user-provided dates.FourierFeatureTransformer: Sin/cos harmonics for cyclical encoding.TimeIndexTransformer: Numeric time index for trend features.FunctionTransformer: Custom function-based transforms.
Examples¶
>>> import polars as pl
>>> from datetime import datetime
>>> time = pl.datetime_range(
... start=datetime(2020, 1, 1), end=datetime(2020, 3, 1), interval="1d", eager=True
... )
>>> X = pl.DataFrame({"time": time, "value": range(len(time))})
>>> transformer = CalendarFeatureTransformer(features=["month", "day_of_week"])
>>> transformer.fit(X)
CalendarFeatureTransformer(features=['month', 'day_of_week'])
>>> X_t = transformer.transform(X)
>>> "cal_month" in X_t.columns
True
Source Code¶
Show/Hide source
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 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 | |
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
|
All non-time output 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.