ExponentialMovingAverage¶
yohou.preprocessing.ExponentialMovingAverage
¶
Bases: BaseActualTransformer
Exponentially Weighted Moving Average (EWMA) transformer.
Computes the exponentially weighted moving average for time series data. The EWMA gives more weight to recent observations with exponentially decreasing weights for older observations.
Parameters ¶
| Name | Type | Description | Default |
|---|---|---|---|
alpha
|
float
|
Smoothing factor (0 < alpha <= 1). Higher values give more weight to recent observations. |
required |
adjust
|
bool
|
If True, uses adjusted weights (divide by decaying adjustment factor). If False, uses standard exponential decay. |
True
|
ignore_nulls
|
bool
|
If True, ignore null values when computing EWMA. If False, propagate null values. |
True
|
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 ¶
The EWMA is commonly used for: - Smoothing noisy time series - Technical indicators (e.g., EMA in finance) - Adaptive feature engineering
Unlike the other window transformers, this transformer is stateless: it has
no internal buffer, so observe/rewind fall through to the base no-op.
Each transform call must therefore receive the full history needed by the
EWMA computation.
Examples ¶
>>> import polars as pl
>>> from datetime import datetime
>>> from yohou.preprocessing import ExponentialMovingAverage
>>> times = pl.datetime_range(
... start=datetime(2020, 1, 1), end=datetime(2020, 1, 10), interval="1d", eager=True
... )
>>> X = pl.DataFrame({"time": times, "value": [1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0]})
>>> transformer = ExponentialMovingAverage(alpha=0.5)
>>> transformer.fit(X)
ExponentialMovingAverage(...)
>>> X_t = transformer.transform(X)
>>> len(X_t) == len(X)
True
See Also ¶
RollingStatisticsTransformer: Fixed-window rolling statistics.SlidingWindowFunctionTransformer: Custom window functions.
Source Code ¶
Source code in src/yohou/preprocessing/window.py
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 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 | |
Methods ¶
get_feature_names_out(input_features=None)
¶
Get output feature names for transformation.
Parameters ¶
| Name | Type | Description | Default |
|---|---|---|---|
input_features
|
list 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/preprocessing/window.py
Tutorials¶
The following example notebooks use this component:
-
How to Apply Window Transformations
Feature engineering with LagTransformer, RollingStatisticsTransformer, SlidingWindowFunctionTransformer, and ExponentialMovingAverage on time series data.
-
How to Compose Features with FeatureUnion
Combine lag features, rolling statistics, EMA, and scaling in parallel with FeatureUnion and automatic observation horizon resolution.