seasonal_emphasis_weight¶
yohou.utils.weighting.seasonal_emphasis_weight(seasonality, emphasis=2.0)
¶
Generate weights emphasizing specific seasonal positions.
Creates a callable that gives higher weights to times matching the most recent seasonal position (e.g., same day of week, same day of month):
where \(s\) is the seasonal period and \(t_n\) is the most recent time.
Parameters¶
| Name | Type | Description | Default |
|---|---|---|---|
seasonality
|
int or list of int
|
Seasonal period(s) (e.g., 7 for weekly, 12 for monthly, or [7, 30] for both weekly and monthly patterns). Determines which times are in-phase with the most recent observation. If multiple seasonalities provided, times matching ANY pattern receive emphasis. |
required |
emphasis
|
float
|
Weight multiplier for in-phase times. In-phase times receive weight
|
2.0
|
Returns¶
| Type | Description |
|---|---|
Callable[[Series], Series]
|
Function accepting time series (datetime) and returning weight series (float64). Times matching the most recent seasonal position(s) receive higher weights. |
See Also¶
exponential_decay_weight: Exponential decay weights for recent times.linear_decay_weight: Linear decay weights for recent times.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), # Monday
... datetime(2024, 1, 2), # Tuesday
... datetime(2024, 1, 8), # Monday (same weekday as most recent)
... datetime(2024, 1, 9), # Tuesday (most recent)
... ],
... )
>>> weight_fn = seasonal_emphasis_weight(seasonality=7, emphasis=2.0)
>>> weights = weight_fn(times)
>>> weights
shape: (4,)
Series: 'weight' [f64]
[
1.0
1.0
1.0
2.0
]
Multiple seasonalities (weekly + monthly):
>>> times = pl.Series("time", [datetime(2024, 1, i) for i in range(1, 32)])
>>> weight_fn = seasonal_emphasis_weight(seasonality=[7, 30], emphasis=2.0)
>>> weights = weight_fn(times)
>>> # Times matching day-of-week OR day-of-month get emphasized
Source Code¶
Show/Hide source
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 290 291 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 | |
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.