SeasonalLogDifferencing¶
yohou.stationarity.SeasonalLogDifferencing
¶
Bases: SeasonalDifferencing, LogTransformer
Seasonal log differencing time series transformer.
Applies log transform followed by seasonal differencing. This combines variance stabilization with seasonal stationarization.
Parameters ¶
| Name | Type | Description | Default |
|---|---|---|---|
seasonality
|
int >= 1
|
Seasonality for the differencing. |
1
|
offset
|
float >= 0.0
|
Offset to apply to the input time series before the log transform. |
0.0
|
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). |
log_transform_ |
LogTransformer
|
Fitted log transform component (internal; used by
|
seasonal_diff_transform_ |
SeasonalDifferencing
|
Fitted seasonal differencing component (internal; used by
|
Examples ¶
>>> import polars as pl
>>> from datetime import datetime
>>> from yohou.stationarity import SeasonalLogDifferencing
>>> X = pl.DataFrame({
... "time": [datetime(2024, 1, i) for i in range(1, 6)],
... "value": [1.0, 2.0, 4.0, 8.0, 16.0],
... })
>>> transformer = SeasonalLogDifferencing(seasonality=1)
>>> transformer.fit(X)
SeasonalLogDifferencing(...)
>>> X_t = transformer.transform(X)
>>> "time" in X_t.columns
True
Notes ¶
This is equivalent to computing log(x_t + offset) - log(x_{t-s} + offset)
which equals log((x_t + offset) / (x_{t-s} + offset)).
This transformer is stateful with observation_horizon = seasonality.
The first seasonality rows are dropped in the output. Inverse
transform requires the X_p prior-context argument (the untransformed
rows preceding the differenced output).
References ¶
- Box, G.E.P., & Cox, D.R. (1964). "An analysis of transformations." Journal of the Royal Statistical Society: Series B, 26(2), 211-252.
- Hyndman, R.J., & Athanasopoulos, G. (2021). "Forecasting: principles and practice," 3rd edition, OTexts: Melbourne, Australia. OTexts.com/fpp3. Chapter 9.1.
See Also ¶
SeasonalDifferencing: Simple seasonal differencing without log transform.LogTransformer: Log transform without differencing.SeasonalReturn: Percentage returns instead of log differences.
Source Code ¶
Source code in src/yohou/stationarity/transformers.py
452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 | |
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:
-
How to Apply Stationarity Transforms
Catalogue of variance-stabilising and detrending transforms: LogTransformer, BoxCox, SeasonalDifferencing, SeasonalReturn, and ASinh with inverse verification.