SeasonalDifferencing¶
yohou.stationarity.SeasonalDifferencing
¶
Bases: BaseActualTransformer
Seasonal differencing time series transformer.
Computes the difference between each value and its value at a seasonal lag:
where \(s\) is the seasonality. This removes seasonal patterns and is
a common stationarization technique.
Parameters ¶
| Name | Type | Description | Default |
|---|---|---|---|
seasonality
|
int >= 1
|
Seasonality for the differencing. |
1
|
Attributes ¶
| Name | Type | Description |
|---|---|---|
n_features_in_ |
int
|
Number of features seen during fit. |
feature_names_in_ |
list of str
|
Names of features seen during fit (excluding "time" column). |
Notes ¶
This transformer is stateful with observation_horizon = seasonality.
The first seasonality rows are dropped in the output since they lack
sufficient history for differencing.
References ¶
- Hyndman, R.J., & Athanasopoulos, G. (2021). "Forecasting: principles and practice," 3rd edition, OTexts: Melbourne, Australia. OTexts.com/fpp3. Chapter 9.1.
Examples ¶
>>> import polars as pl
>>> from datetime import datetime
>>> from yohou.stationarity import SeasonalDifferencing
>>> X = pl.DataFrame({
... "time": [datetime(2020, 1, i) for i in range(1, 8)],
... "value": [10.0, 12.0, 15.0, 13.0, 11.0, 14.0, 16.0],
... })
>>> # First-order differencing (seasonality=1)
>>> transformer = SeasonalDifferencing(seasonality=1)
>>> transformer.fit(X)
SeasonalDifferencing(...)
>>> X_diff = transformer.transform(X)
>>> len(X_diff) # One row dropped
6
See Also ¶
SeasonalLogDifferencing: Log transform followed by seasonal differencing.SeasonalReturn: Compute seasonal returns ((x_t - x_{t-s}) / x_{t-s}).
Source Code ¶
Source code in src/yohou/stationarity/transformers.py
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 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 | |
Methods ¶
observation_horizon
property
¶
Return the number of past observations needed.
get_feature_names_out(input_features=None)
¶
Get output feature names for transformation.
Parameters ¶
| Name | Type | Description | Default |
|---|---|---|---|
input_features
|
array-like of str or None
|
Column names of the input features. If |
None
|
Returns ¶
| Type | Description |
|---|---|
list of str
|
Output feature names after transformation. |
Source Code ¶
Source code in src/yohou/stationarity/transformers.py
Tutorials¶
The following example notebooks use this component:
-
Forecasting Workflow
Evaluate forecasters with cross-validation, search hyperparameters with GridSearchCV, and inspect residuals to diagnose model weaknesses.
-
How to Apply Stationarity Transforms
Catalogue of variance-stabilising and detrending transforms: LogTransformer, BoxCox, SeasonalDifferencing, SeasonalReturn, and ASinh with inverse verification.
-
How to Apply Stationarity to Panel Data
Apply per-group stationarity transforms on panel data with SeasonalDifferencing, DecompositionPipeline (polynomial trend + pattern seasonality), and residuals.
-
How to Score Multi-Vintage Forecasts
Generate multi-vintage predictions with observe_predict, score per step and per vintage, and visualize with heatmap, per-step, and per-vintage plots.
-
Interval Forecasting
Wrap a point forecaster with SplitConformalForecaster to produce 95% prediction intervals with statistical coverage guarantees.
-
Quickstart
Comprehensive end-to-end tour of yohou beyond the Getting Started tutorials, covering data loading, baseline forecasting, preprocessing pipelines, decomposition, cross-validation search, and interval prediction.