SeasonalEmphasisWeighter¶
yohou.weighting.SeasonalEmphasisWeighter
¶
Bases: BaseWeighter
Weights emphasizing keys in phase with the most recent seasonal position.
Gives higher weight to keys whose ordinal rank shares the same value modulo
the seasonal period as the most-recent key. This coincides with "same
weekday" (for seasonality=7) only when the series is contiguous and its
length is an exact multiple of the period; in general it is a rank-phase
match, not a calendar match. Rank-based, so usable for datetime or integer
keys.
Parameters ¶
| Name | Type | Description | Default |
|---|---|---|---|
seasonality
|
int or list of int
|
Seasonal period(s). If a list, keys matching ANY period receive emphasis.
With |
1
|
emphasis
|
float
|
Weight multiplier for in-phase keys (out-of-phase keys receive 1.0). |
2.0
|
See Also ¶
ExponentialDecayWeighter: Exponential recency weighting.LinearDecayWeighter: Linear recency weighting.CompositeWeighter: Combine weighters by product or mean.
Examples ¶
>>> import polars as pl
>>> from datetime import datetime
>>> times = pl.Series(
... "time",
... [datetime(2024, 1, 1), datetime(2024, 1, 2), datetime(2024, 1, 8), datetime(2024, 1, 9)],
... )
>>> SeasonalEmphasisWeighter(seasonality=7).compute_weights(times)
shape: (4,)
Series: 'weight' [f64]
[
1.0
1.0
1.0
2.0
]
Source Code ¶
Source code in src/yohou/weighting/weighters.py
292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 | |
Methods ¶
compute_weights(key, group_name=None)
¶
Compute seasonal emphasis weights for key.
Source Code ¶
Source code in src/yohou/weighting/weighters.py
Tutorials¶
The following example notebooks use this component:
-
How to Apply Time-Weighted Training
Use time_weight and sample_weight_alignment to emphasise recent or seasonal training samples in PointReductionForecaster, with visualisation of weight curves and alignment strategy comparison.
-
How to Score with Time-Weighted Metrics
Apply exponential decay, linear decay, and seasonal emphasis weighting to forecast evaluation, prioritising recent or periodic time steps.