Skip to content

Clustering, density estimation, and anomaly detection · Anomaly detection · UCL058 · Algorithm

Minimum Covariance Determinant Mahalanobis detector

Estimate a robust ellipsoidal reference distribution and score deviations using robust Mahalanobis distance. It is useful when normal observations form one roughly elliptical population with limited contamination.

Runs in CodeSplash Component demo, not a trained model CodeSplash's run and the reference's record

In CodeSplash

A CodeSplash method runs this entry in Python and R. Set it up from the method's page.

Do it in CodeSplash Run it on your own data, in Python or R.

Availability
Runs in CodeSplash
Code example
Component demo, not a trained model
Who ran it
CodeSplash's run and the reference's record
CodeSplash's run
Verified in Python and R through discover.robust_cov. The reference's example ran in Python and R here, and they agree.
The reference's record
Python: Ran in the reference's review. The report doesn't record which version of the code ran. R: Reviewed but not run: R wasn't available to the reference's authors.

Purpose

Estimate a robust ellipsoidal reference distribution and score deviations using robust Mahalanobis distance. It is useful when normal observations form one roughly elliptical population with limited contamination.

Question / hypotheses

Which observations deviate from the chosen reference notion of normality, and at what operational alert rate? This entry defines an estimation or optimization objective, not an intrinsic null/alternative hypothesis test.

Architecture / computational structure

Robust subset covariance estimation followed by quadratic distance scoring.

Assumptions

Robust covariance still requires enough observations relative to dimension and a nonsingular geometry. Multimodal normal data can be poorly represented by one ellipsoid. Chi-square thresholds need distributional and estimation qualifications; they are not universally exact finite-sample tests.

Formula / computational definition

MCD selects an hh-observation subset minimizing the determinant of its covariance matrix, followed by correction/reweighting in practical implementations. With robust location μ^\hat\mu and covariance Σ^\hat\Sigma, the score is D2(x)=(x−μ^)TΣ^−1(x−μ^)D^2(x)=(x-\hat\mu)^T\hat\Sigma^{-1}(x-\hat\mu).

Parameters and notation

Learned or fitted quantities: Robust center, covariance, and an externally chosen threshold. User-set hyperparameters/design choices: Choose support fraction, preprocessing, regularization strategy if necessary, and threshold calibration. Tune these against the stated objective and stability/validation criteria; do not select settings on the final evaluation set.

Fitting, fine-tuning, and adaptation

Neural fine-tuning is not applicable to this classical detector. Refit the reference model when its population changes, then recalibrate an alert threshold on a separate normal holdout. Tune sensitivity without using final-test anomaly labels repeatedly.

How to use and calibrate

Inspect robust versus ordinary covariance, eigenvalues, normal holdout coverage, and flagged subgroups. Compare with local or mixture detectors when normal structure is heterogeneous.

Example application

Screen a roughly elliptical process using robust location and covariance. Define the reference population, measurement units, and success criterion before fitting; investigate whether discovered groups or alerts reflect the intended phenomenon.

Interpretation / pitfalls

Watch out

The reported result is conditional on the representation and objective. An alert is a screening result, not a diagnosis or a calibrated posterior probability. Evaluate both ranking and the decision threshold.

Python and R code examples

Python sklearn.covariance.MinCovDet estimates the robust parameters. R can bridge to it or use a separately verified robust-covariance implementation. The component code computes distances given robust estimates, explicitly separating scoring from MCD subset search.

Component: Mahalanobis scoring with supplied robust estimates. Python: executed successfully; R: not executed (Rscript unavailable). These small fixtures establish the arithmetic operation, not full-method accuracy or reproduction of paper results.

Python and R

The reference's own programs, shown as written. A component demo shows one central piece of the method; it doesn't train a full model.

Python

Component demo, not a trained model — Mahalanobis scoring with supplied robust estimates. · needs numpy

import numpy as np
X=np.array([[0.,0.],[1.,1.],[4.,0.]]); mu=np.array([0.,0.]); cov=np.array([[1.,.2],[.2,1.]])
V=X-mu; result=np.einsum('ij,jk,ik->i',V,np.linalg.inv(cov),V)
print(result)
R

Component demo, not a trained model — Mahalanobis scoring with supplied robust estimates.

X=rbind(c(0,0),c(1,1),c(4,0)); mu=c(0,0); covariance=rbind(c(1,.2),c(.2,1))
V=sweep(X,2,mu); result=rowSums((V%*%solve(covariance))*V)
print(result)

Sources

From the CodeSplash reference, entry UCL058.