polars.Series.ewm_mean
-
Compute exponentially-weighted moving average.
Changed in version 1.21.0: The
min_periodsparameter was renamedmin_samples.- Parameters:
-
- com
-
Specify decay in terms of center of mass, \(\gamma\), with
\[\alpha = \frac{1}{1 + \gamma} \; \forall \; \gamma \geq 0\] - span
-
Specify decay in terms of span, \(\theta\), with
\[\alpha = \frac{2}{\theta + 1} \; \forall \; \theta \geq 1\] - half_life
-
Specify decay in terms of half-life, \(\tau\), with
\[\alpha = 1 - \exp \left\{ \frac{ -\ln(2) }{ \tau } \right\} \; \forall \; \tau > 0\] - alpha
-
Specify smoothing factor alpha directly, \(0 < \alpha \leq 1\).
- adjust
-
Divide by decaying adjustment factor in beginning periods to account for imbalance in relative weightings
- When
adjust=True(the default) the EW function is calculated using weights \(w_i = (1 - \alpha)^i\) -
When
adjust=Falsethe EW function is calculated recursively by\[\begin{split}y_0 &= x_0 \\ y_t &= (1 - \alpha)y_{t - 1} + \alpha x_t\end{split}\]
- When
- min_samples
-
Minimum number of observations in window required to have a value (otherwise result is null).
- ignore_nulls
-
Ignore missing values when calculating weights.
- When
ignore_nulls=False(default), weights are based on absolute positions. For example, the weights of \(x_0\) and \(x_2\) used in calculating the final weighted average of [\(x_0\), None, \(x_2\)] are \((1-\alpha)^2\) and \(1\) ifadjust=True, and \((1-\alpha)^2\) and \(\alpha\) ifadjust=False. - When
ignore_nulls=True, weights are based on relative positions. For example, the weights of \(x_0\) and \(x_2\) used in calculating the final weighted average of [\(x_0\), None, \(x_2\)] are \(1-\alpha\) and \(1\) ifadjust=True, and \(1-\alpha\) and \(\alpha\) ifadjust=False.
- When
Examples
>>> s = pl.Series([1, 2, 3]) >>> s.ewm_mean(com=1, ignore_nulls=False) shape: (3,) Series: '' [f64] [ 1.0 1.666667 2.428571 ]
Series.ewm_mean(
*,
com: float | None = None,
span: float | None = None,
half_life: float | None = None,
alpha: float | None = None,
adjust: bool = True,
min_samples: int = 1,
ignore_nulls: bool = False,
) → Series
© 2020 Ritchie Vink
© 2022 Polars contributors
Licensed under the MIT License.
https://docs.pola.rs/api/python/stable/reference/series/api/polars.Series.ewm_mean.html