SeasonalDifferencing¶
yohou.stationarity.transformers.SeasonalDifferencing
¶
Bases: BaseTransformer
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. |
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¶
[1] 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¶
Show/Hide source
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 338 339 340 341 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 | |
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¶
Show/Hide source
Tutorials¶
The following example notebooks use this component:
-
How to Apply Stationarity Transforms
Data-Features
Catalogue of variance-stabilising and detrending transforms: LogTransformer, BoxCox, SeasonalDifferencing, SeasonalReturn, and ASinh with inverse verification.
-
How to Score Multi-Vintage Forecasts
Evaluation-Search
Generate multi-vintage predictions with observe_predict, score per step and per vintage, and visualize with heatmap, per-step, and per-vintage plots.
-
Forecasting Workflow
Getting-Started
Evaluate forecasters with cross-validation, search hyperparameters with GridSearchCV, and inspect residuals to diagnose model weaknesses.
-
Interval Forecasting
Getting-Started
Wrap a point forecaster with SplitConformalForecaster to produce 95% prediction intervals with statistical coverage guarantees.
-
How to Apply Stationarity to Panel Data
Panel-Data
Apply per-group stationarity transforms on panel data with SeasonalDifferencing, DecompositionPipeline (polynomial trend + pattern seasonality), and residuals.
-
Quickstart
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.