ExponentialMovingAverage¶
yohou.preprocessing.window.ExponentialMovingAverage
¶
Bases: BaseTransformer
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
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¶
Show/Hide source
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 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 | |
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¶
Show/Hide source
Tutorials¶
The following example notebooks use this component:
-
How to Compose Features with FeatureUnion
Data-Features
Combine lag features, rolling statistics, EMA, and scaling in parallel with FeatureUnion and automatic observation horizon resolution.
-
How to Apply Window Transformations
Data-Features
Feature engineering with LagTransformer, RollingStatisticsTransformer, SlidingWindowFunctionTransformer, and ExponentialMovingAverage on time series data.