Skip to content

做什么(One-liner)

标准化值 z = (v - μ) / σ,零方差返回 None。库级 primitive。

怎么用

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

核心公式

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)

假设与适用场景

假设:series 是参考分布 + ddof=0 + 零方差兜底 None。

适用:factor 标准化、异常检测、ML pre-processing。

不适用:streaming、非正态解释、厚尾。

已知局限

  1. 零方差 None 兜底(BUG-GOLDEN-001 修复)
  2. 非 streaming
  3. 厚尾低估

参考文献

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 修复(np.ptp==0 零方差守卫)+ 首次 Active

Verifiable intelligence for the decisions that demand scrutiny.