LinearDecayWeighter¶
yohou.weighting.LinearDecayWeighter
¶
Bases: BaseWeighter
Linear decay weights giving more weight to recent keys.
Computes rank-based linear decay. When max_steps is None:
where \(\text{rank}(k) = 0\) for the oldest key and \(n - 1\) for the most
recent. When max_steps is set, the denominator becomes
max_steps - 1 and the window is shifted:
so only the max_steps - 1 most-recent keys receive a strictly positive
weight; the boundary key at rank n - max_steps maps to exactly 0.0, as
do all older keys. Rank-based, so usable for datetime or integer keys
without a scale parameter.
Parameters ¶
| Name | Type | Description | Default |
|---|---|---|---|
max_steps
|
int or None
|
Window over which to decay. If None, decays linearly across the whole
range. If set, keys at rank |
None
|
See Also ¶
ExponentialDecayWeighter: Exponential recency weighting.SeasonalEmphasisWeighter: Seasonal emphasis weighting.CompositeWeighter: Combine weighters by product or mean.
Examples ¶
>>> import polars as pl
>>> from datetime import datetime
>>> times = pl.Series("time", [datetime(2024, 1, d) for d in range(1, 5)])
>>> LinearDecayWeighter().compute_weights(times)
shape: (4,)
Series: 'weight' [f64]
[
0.0
0.333333
0.666667
1.0
]
Source Code ¶
Source code in src/yohou/weighting/weighters.py
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 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 | |
Methods ¶
compute_weights(key, group_name=None)
¶
Compute linear decay 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.