Implementation:Online ml River Stats Kurtosis
| Knowledge Sources | |
|---|---|
| Domains | Online_Learning, Statistics |
| Last Updated | 2026-02-08 16:00 GMT |
Overview
Kurtosis computes the running kurtosis of a data stream using Welford's algorithm.
Description
This statistic measures the "tailedness" of a distribution - whether data tends to have heavy or light tails compared to a normal distribution. It calculates the fourth standardized moment incrementally. The implementation uses Rust for performance and supports both biased and unbiased estimators through the bias parameter. Positive kurtosis indicates heavy tails with more outliers, while negative kurtosis indicates light tails.
Usage
Use Kurtosis when you need to understand the tail behavior of streaming data distributions. This is useful in risk assessment, quality control, anomaly detection, and financial analysis where understanding the likelihood of extreme values is important. It helps identify distributions with more or fewer outliers than expected.
Code Reference
Source Location
- Repository: Online_ml_River
- File: river/stats/kurtosis.py
Signature
class Kurtosis(stats.base.Univariate):
def __init__(self, bias=False):
super().__init__()
self.bias = bias
self._kurtosis = _rust_stats.RsKurtosis(bias)
Import
from river import stats
I/O Contract
Inputs
| Name | Type | Required | Description |
|---|---|---|---|
| x | numbers.Number | Yes | Value to update the statistic with |
| bias | bool | Yes (init) | If False, calculations are corrected for statistical bias (default: False) |
Outputs
| Name | Type | Description |
|---|---|---|
| get() | float | Current kurtosis value (excess kurtosis, 0 for normal distribution) |
Usage Examples
from river import stats
import numpy as np
np.random.seed(42)
X = np.random.normal(loc=0, scale=1, size=10)
# Unbiased kurtosis
kurtosis = stats.Kurtosis(bias=False)
for x in X:
kurtosis.update(x)
print(f"Kurtosis: {kurtosis.get():.4f}")
# Output (final values):
# -3.0
# -2.0
# -1.5
# 1.4130
# 0.1537
# 0.4614
# -1.6206
# -1.3540
# -1.2310
# -0.9490
# Biased kurtosis
kurtosis_biased = stats.Kurtosis(bias=True)
for x in X:
kurtosis_biased.update(x)
print(f"Biased Kurtosis: {kurtosis_biased.get():.4f}")
# Detecting heavy-tailed distributions
heavy_tail = stats.Kurtosis()
# Add data with outliers
for x in [1, 2, 3, 4, 5, 100]: # 100 is an outlier
heavy_tail.update(x)
print(f"Kurtosis with outlier: {heavy_tail.get():.4f}")
# Positive value indicates heavy tails