linear_decay_weight¶
yohou.utils.weighting.linear_decay_weight(max_steps=None)
¶
Generate linear decay weights giving more weight to recent times.
Creates a callable that computes weights using linear decay:
where \(\text{rank}(t) = 0\) for the oldest observation and \(n - 1\)
for the most recent. When max_steps is set, observations older
than max_steps receive weight 0.
Parameters¶
| Name | Type | Description | Default |
|---|---|---|---|
max_steps
|
int or None
|
Maximum number of steps to decay over. If None, decays linearly across entire time range. If specified, times older than max_steps from the most recent time receive weight 0. |
None
|
Returns¶
| Type | Description |
|---|---|
Callable[[Series], Series]
|
Function accepting time series (datetime) and returning weight series (float64). Most recent time has weight 1.0, weights decrease linearly. |
See Also¶
exponential_decay_weight: Exponential decay weights for recent times.seasonal_emphasis_weight: Weights emphasizing seasonal positions.compose_weights: Compose multiple weight functions by multiplication.validate_callable_signature: Validate callable signature for time weighting.BaseReductionForecaster: Reduction forecaster supporting time_weight.
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),
... datetime(2024, 1, 4),
... ],
... )
>>> weight_fn = linear_decay_weight(max_steps=None)
>>> weights = weight_fn(times)
>>> weights
shape: (4,)
Series: 'weight' [f64]
[
0.0
0.333333
0.666667
1.0
]
Source Code¶
Show/Hide source
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 | |
Tutorials¶
The following example notebooks use this component:
-
How to Apply Time-Weighted Training
Forecasting-Models
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.