SeasonalReturn¶
yohou.stationarity.transformers.SeasonalReturn
¶
Bases: BaseTransformer
Seasonal percentage return time series transformer.
Computes the percentage return relative to the value from seasonality
time steps ago:
This is useful for modeling relative changes in time series with seasonal patterns, such as year-over-year percentage growth.
Parameters¶
| Name | Type | Description | Default |
|---|---|---|---|
seasonality
|
int > 1
|
Seasonality lag for computing returns. |
1
|
offset
|
float >= 0.0
|
Offset to apply to avoid division by zero. Should be positive if data contains zeros or near-zero values. |
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). |
Examples¶
>>> import polars as pl
>>> from datetime import datetime
>>> from yohou.stationarity import SeasonalReturn
>>> X = pl.DataFrame({
... "time": [datetime(2024, 1, i) for i in range(1, 6)],
... "value": [100.0, 110.0, 105.0, 115.0, 120.0],
... })
>>> transformer = SeasonalReturn(seasonality=2, offset=0.0)
>>> transformer.fit(X)
SeasonalReturn(...)
>>> X_t = transformer.transform(X)
>>> len(X_t) == len(X) - 2 # First 2 rows dropped
True
References¶
[1] Hyndman, R.J., & Athanasopoulos, G. (2021). "Forecasting: principles and practice," 3rd edition, OTexts: Melbourne, Australia. OTexts.com/fpp3. Chapter 9.1.
See Also¶
AbsoluteSeasonalReturn: Absolute difference instead of percentage return.SeasonalDifferencing: Simple differencing without percentage computation.SeasonalLogDifferencing: Log-differencing for multiplicative relationships.
Source Code¶
Show/Hide source
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 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 | |
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.