ExponentialDecayWeighter¶
yohou.weighting.ExponentialDecayWeighter
¶
Bases: BaseWeighter
Exponential decay weights giving more weight to recent keys.
Computes weights via exponential decay from the most recent key:
where \(d(k)\) is the distance from the most recent key. With
scale="elapsed" the distance is the real elapsed time to the most recent
datetime; with scale="position" it is the rank-index distance (usable for
integer forecasting steps or regularly-spaced time).
Parameters ¶
| Name | Type | Description | Default |
|---|---|---|---|
half_life
|
int, float, or datetime.timedelta
|
Distance over which weight decays to half. With |
1
|
scale
|
('elapsed', 'position')
|
Decay basis. |
"elapsed"
|
Notes ¶
The most recent (largest) key receives weight 1.0; smaller keys decay.
References ¶
- Hyndman, R.J., & Athanasopoulos, G. (2021). "Forecasting: principles and practice," 3rd edition, OTexts. Chapter 8.1.
See Also ¶
LinearDecayWeighter: Linear 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, 1), datetime(2024, 1, 2), datetime(2024, 1, 3)],
... )
>>> ExponentialDecayWeighter(half_life=1).compute_weights(times)
shape: (3,)
Series: 'weight' [f64]
[
0.25
0.5
1.0
]
Source Code ¶
Source code in src/yohou/weighting/weighters.py
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 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 | |
Methods ¶
compute_weights(key, group_name=None)
¶
Compute exponential 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 Handle Long Series
Limit history with observation_horizon, weight recent errors with exponential decay, and downsample high-frequency data.
-
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.