Skip to main content
← Lab

grandmean

confirmedupstream bugPython · evaluateInference & servingJuly 24, 2026

the question

Does HuggingFace evaluate's mahalanobis metric center inputs with a per-feature mean?

what came out

HuggingFace evaluate mahalanobis.py centers with X - np.mean(reference_distribution), the scalar grand mean, against a per-feature np.cov, so the quadratic form mixes bases. A point at the distribution center gets D^2=52.48 instead of 0, and error grows with feature-mean spread. Fix is np.mean(..., axis=0).

method & receipts

  • Result: confirmed
  • Reproducible one script re-runs the whole thing from scratch.
  • Tested — a correctness/benchmark suite ships alongside the code.

→ read the code and re-run it

github.com/v-code01/grandmean