Skip to content

What (One-liner)

Standardize value z = (v - μ) / σ, zero variance returns None. Library-level primitive.

How to use

python
from services.algo.statistics import z_score
z_score(70, [50, 60, 70, 80, 90])   # 0.0 (at mean)
z_score(100, [50, 60, 70, 80, 90])  # ~2.12

Core formulas

filtered = [x for x in series if x is not None]
if np.ptp(filtered) == 0: return None
z = (value - np.mean(filtered)) / np.std(filtered, ddof=0)

Assumptions & applicability

Assumptions: series is reference distribution + ddof=0 + zero variance fallback None.

Applicable: factor standardization, anomaly detection, ML pre-processing.

Not Applicable: streaming, non-normal interpretation, heavy tails.

Known limitations

  1. Zero variance None fallback (BUG-GOLDEN-001 fix)
  2. Non-streaming
  3. Heavy tail underestimation

References

Rice (2006) Mathematical Statistics and Data Analysis.

Golden Test

tests/golden/fixtures/tier1/z_score/, 1e-12, 2026-04-20 passing.

Changelog

  • 1.0.0 (2026-04-20) — BUG-GOLDEN-001 fix (np.ptp==0 zero variance guard) + first Active

Verifiable intelligence for the decisions that demand scrutiny.