Robust Covariance (Minimum Covariance Determinant)

Estimate the mean and covariance from the h most tightly packed points — the subset with the smallest covariance determinant — so outliers cannot inflate the ellipse that is supposed to expose them.

22 min read1463 wordsadvanced0 viewsupdated 2026-10-08

Definition

The Minimum Covariance Determinant (MCD) estimator looks for the hh out of nn points whose sample covariance has the smallest determinant, and reports their mean and (rescaled) covariance as the location and scatter of the data. Because it only ever uses the most concentrated half of the points, up to roughly half of the data can be arbitrarily bad without dragging the estimate away.

At a glance

Task
Robust estimation of location μ\mu and scatter Σ\Sigma; the basis of outlier detection with Mahalanobis distances
Input → output
n×pn\times p data → μ^MCD\hat\mu_{\text{MCD}}, Σ^MCD\hat\Sigma_{\text{MCD}}, and a robust distance did_i for every point
Objective
min⁡∣H∣=hdet⁡Σ^H\min_{|H|=h}\det\hat\Sigma_H — the tightest hh-point ellipsoid
Algorithm
FAST-MCD: random starts + C-steps (each step never increases the determinant), then consistency correction and reweighting
Breakdown point
up to ⌊(n−p+1)/2⌋/n≈50%\lfloor (n-p+1)/2\rfloor / n\approx 50\%, versus 1/n1/n for the sample mean and covariance
Hyperparameter
hh (scikit-learn: support_fraction =h/n=h/n); default h≈(n+p+1)/2h\approx (n+p+1)/2
Equivariance
affine equivariant: rescaling, rotating or shifting the features transforms the estimate the same way — no standardization needed
Assumes
the bulk is roughly elliptical (Gaussian-like), n>2pn > 2p or so, and the data are not concentrated on a lower-dimensional subspace

The problem: outliers hide themselves

The standard way to find multivariate outliers is the Mahalanobis distance: fit a mean and covariance, then measure how many "standard deviations" each point is from the centre, in the shape of the data. Under a Gaussian model the squared distance follows a χp2\chi^2_p distribution, so anything above, say, its 97.5% quantile is suspicious.

d2(xi)=(xi−μ^)⊤Σ^−1(xi−μ^)  ∼Gaussian  χp2,flag if d2(xi)>χp, 0.9752d^2(x_i)=(x_i-\hat\mu)^\top\hat\Sigma^{-1}(x_i-\hat\mu)\;\overset{\text{Gaussian}}{\sim}\;\chi^2_p,\qquad \text{flag if } d^2(x_i)>\chi^2_{p,\,0.975}
μ^, Σ^\hat\mu,\ \hat\Sigma
estimated mean vector and covariance matrix
χp2\chi^2_p
chi-square distribution with pp degrees of freedom (pp = number of features)
χ2, 0.9752\chi^2_{2,\,0.975}
=7.38=7.38 for p=2p=2 (its CDF is 1−e−x/21-e^{-x/2}, so the quantile is −2ln⁡0.025-2\ln 0.025)

The catch is circular: μ^\hat\mu and Σ^\hat\Sigma are estimated from the same data that contains the outliers. A small group of outliers pulls the mean toward itself and stretches the covariance in its own direction. The ellipse grows to swallow them, their distances shrink, and they stop looking unusual. This is called masking. Its mirror image, swamping, is when the distorted ellipse pushes perfectly ordinary points outside the cutoff.

The MCD estimator

Rousseeuw's idea (1984): instead of fitting all points, find the subset of hh points that is most tightly concentrated and fit only those. "Tight" is measured by the determinant of the subset's covariance, which is proportional to the squared volume of its tolerance ellipsoid.

H^=arg⁡min⁡H⊂{1..n}, ∣H∣=h det⁡Σ^H,μ^H=1h∑i∈Hxi,Σ^H=1h∑i∈H(xi−μ^H)(xi−μ^H)⊤\hat H=\arg\min_{H\subset\{1..n\},\ |H|=h}\ \det\hat\Sigma_H,\qquad \hat\mu_H=\frac1h\sum_{i\in H}x_i,\quad \hat\Sigma_H=\frac1h\sum_{i\in H}(x_i-\hat\mu_H)(x_i-\hat\mu_H)^\top
HH
a subset of hh point indices (the "support")
det⁡Σ^H\det\hat\Sigma_H
generalized variance of the subset; the ellipsoid {x:dH2(x)≤c}\{x: d^2_H(x)\le c\} has volume ∝det⁡Σ^H\propto\sqrt{\det\hat\Sigma_H}
μ^H, Σ^H\hat\mu_H,\ \hat\Sigma_H
the raw MCD location and scatter: plain mean and covariance of the chosen subset
h=⌊n+p+12⌋,ε∗(h)=min⁡(n−h+1, h−p)n → h = ⌊(n+p+1)/2⌋  ⌊(n−p+1)/2⌋n≈12h=\left\lfloor\frac{n+p+1}{2}\right\rfloor,\qquad \varepsilon^*(h)=\frac{\min(n-h+1,\ h-p)}{n}\ \xrightarrow{\ h\,=\,\lfloor (n+p+1)/2\rfloor\ }\ \frac{\lfloor (n-p+1)/2\rfloor}{n}\approx\frac12
hh
subset size; this choice maximizes the breakdown point
ε∗\varepsilon^*
finite-sample breakdown point: the smallest fraction of points that, replaced by arbitrary values, can make the estimate useless
n−h+1n-h+1
contaminating this many points forces at least one into every h-subset
h−ph-p
a subset needs more than p good points to keep a non-degenerate covariance

Why does it resist outliers? As long as fewer than n−h+1n-h+1 points are bad, there exists an hh-subset made only of good points, and any subset that includes far-away points has a much larger determinant — so the minimizer avoids them. For our example (n=12n=12, p=2p=2): h=7h=7 and ε∗=min⁡(6,5)/12=5/12≈42%\varepsilon^*=\min(6,5)/12=5/12\approx 42\%. Five arbitrary outliers can't break it; the sample covariance is broken by one.

hBreakdown pointEfficiency on clean Gaussian dataWhen
≈(n+p+1)/2\approx (n+p+1)/2≈ 50% (maximum)lowest: uses only half the pointscontamination unknown, could be large
≈0.75 n\approx 0.75\,n≈ 25%noticeably betteryou know contamination is modest
nn1/n1/n (none)best (it is the classical estimate)no outliers — then why bother?
Choosing h is a robustness–efficiency dial.

The C-step: a descent move on subsets

There are (nh)\binom{n}{h} subsets — 792 for our toy problem, astronomically many for real data — so exhaustive search is out. The key tool is the concentration step (C-step) of Rousseeuw & Van Driessen (1999): given any hh-subset, compute its mean and covariance, measure every point's distance under that fit, and take the hh closest points as the new subset.

Hk+1={the h indices with smallest dk2(xi)},dk2(x)=(x−μ^k)⊤Σ^k−1(x−μ^k)H_{k+1}=\big\{\text{the } h \text{ indices with smallest } d_k^2(x_i)\big\},\qquad d_k^2(x)=(x-\hat\mu_k)^\top\hat\Sigma_k^{-1}(x-\hat\mu_k)
HkH_k
current subset, with mean μ^k\hat\mu_k and covariance Σ^k\hat\Sigma_k
dk2d_k^2
squared Mahalanobis distance of every point (all n, not just the subset) under the current fit

Proof sketch

  1. 1Old points average to pp. For any set, 1h∑i∈Hkdk2(xi)=tr⁡(Σ^k−1Σ^k)=p\frac1h\sum_{i\in H_k}d_k^2(x_i)=\operatorname{tr}\big(\hat\Sigma_k^{-1}\hat\Sigma_k\big)=p. Because Hk+1H_{k+1} takes the hh smallest dk2d_k^2, 1h∑i∈Hk+1dk2(xi)≤p\frac1h\sum_{i\in H_{k+1}}d_k^2(x_i)\le p.
  2. 2Re-centring only helps. The mean μ^k+1\hat\mu_{k+1} minimizes the sum of any quadratic form over Hk+1H_{k+1}, so measuring around μ^k+1\hat\mu_{k+1} instead of μ^k\hat\mu_k can only lower it: tr⁡(Σ^k−1Σ^k+1)=1h∑i∈Hk+1(xi−μ^k+1)⊤Σ^k−1(xi−μ^k+1)≤p\operatorname{tr}\big(\hat\Sigma_k^{-1}\hat\Sigma_{k+1}\big)=\frac1h\sum_{i\in H_{k+1}}(x_i-\hat\mu_{k+1})^\top\hat\Sigma_k^{-1}(x_i-\hat\mu_{k+1})\le p.
  3. 3AM–GM on eigenvalues. Let λ1..λp>0\lambda_1..\lambda_p>0 be the eigenvalues of Σ^k−1Σ^k+1\hat\Sigma_k^{-1}\hat\Sigma_{k+1}. Then det⁡(Σ^k−1Σ^k+1)=∏λj≤(1p∑λj)p≤1\det\big(\hat\Sigma_k^{-1}\hat\Sigma_{k+1}\big)=\prod\lambda_j\le\big(\tfrac1p\sum\lambda_j\big)^p\le 1.
  4. 4Conclude. det⁡Σ^k+1≤det⁡Σ^k\det\hat\Sigma_{k+1}\le\det\hat\Sigma_k. Equality needs every λj=1\lambda_j=1, i.e. Σ^k+1=Σ^k\hat\Sigma_{k+1}=\hat\Sigma_k.

The C-step is to MCD what the assign/update loop is to k-means: a monotone descent that is guaranteed to stop, but only at a local minimum. Where it ends depends on where it starts.

FAST-MCD

FAST-MCD (Rousseeuw & Van Driessen, 1999)

  1. 1Many cheap starts. Draw a random (p+1)(p+1)-subset JJ (the smallest set with a non-singular covariance; enlarge it if its determinant is 0). Fit μ^J,Σ^J\hat\mu_J,\hat\Sigma_J and take the hh closest points as H1H_1. Small starts matter: a random hh-subset almost surely contains outliers when contamination is high, but a 3-point start is often clean.
  2. 2Two C-steps each, then keep only the ~10 subsets with the lowest determinant.
  3. 3Iterate the survivors to convergence and keep the overall winner: the raw MCD (μ^raw,Σ^raw)(\hat\mu_{\text{raw}},\hat\Sigma_{\text{raw}}).
  4. 4Large n: split the data into disjoint groups of ~300, run the above inside each group, pool the best candidates on a merged sample of ~1500, then finish on the full data. Cost is roughly linear in nn.
  5. 5Correct and reweight (next section).

Consistency correction and reweighting

The raw MCD covariance is too small. By construction it is computed from the hh most central points, so it estimates the covariance of a truncated Gaussian. Two fixes follow.

Σ^MCD=c Σ^raw,c=h/nP ⁣(χp+22≤χp, h/n2)or, empirically,c=median⁡i draw2(xi)χp, 0.52\hat\Sigma_{\text{MCD}}=c\,\hat\Sigma_{\text{raw}},\qquad c=\frac{h/n}{P\!\left(\chi^2_{p+2}\le\chi^2_{p,\,h/n}\right)}\quad\text{or, empirically,}\quad c=\frac{\operatorname{median}_i\,d^2_{\text{raw}}(x_i)}{\chi^2_{p,\,0.5}}
cc
consistency factor: makes the estimate unbiased for Σ when the data really are Gaussian
χp, h/n2\chi^2_{p,\,h/n}
the h/nh/n quantile of χp2\chi^2_p: the squared radius that contains a fraction h/nh/n of a Gaussian
χp+22\chi^2_{p+2}
arises because E[XX⊤ 1{d2≤q}]=P(χp+22≤q) ΣE[XX^\top\,\mathbf 1\{d^2\le q\}]=P(\chi^2_{p+2}\le q)\,\Sigma for X∼N(0,Σ)X\sim N(0,\Sigma)
χp, 0.52\chi^2_{p,\,0.5}
median of χp2\chi^2_p; 2ln⁡2=1.3862\ln 2=1.386 for p=2p=2. scikit-learn uses this median rule

The median rule asks: after rescaling, does the median point have the median distance a Gaussian would give it? It is robust (the median ignores outliers), adapts to finite samples, and is what scikit-learn uses. The asymptotic formula (Croux & Haesbroeck, 1999) is what R's robustbase uses, together with an extra small-sample factor.

wi=1 ⁣{dMCD2(xi)≤χp, 0.9752},μ^RW=∑iwixi∑iwi,Σ^RW=∑iwi(xi−μ^RW)(xi−μ^RW)⊤∑iwiw_i=\mathbf 1\!\left\{d^2_{\text{MCD}}(x_i)\le\chi^2_{p,\,0.975}\right\},\qquad \hat\mu_{\text{RW}}=\frac{\sum_i w_i x_i}{\sum_i w_i},\qquad \hat\Sigma_{\text{RW}}=\frac{\sum_i w_i (x_i-\hat\mu_{\text{RW}})(x_i-\hat\mu_{\text{RW}})^\top}{\sum_i w_i}
wiw_i
hard weight: 1 if the point looks regular under the corrected MCD, 0 if it is flagged
μ^RW, Σ^RW\hat\mu_{\text{RW}},\ \hat\Sigma_{\text{RW}}
reweighted (final) estimates: ordinary mean and covariance of every non-flagged point

Reweighting recovers efficiency. The raw MCD threw away n−hn-h points even if they were perfectly good; reweighting brings back every point that the robust fit says is regular, keeping the high breakdown point while using far more data. The final robust distances dRW2(xi)d^2_{\text{RW}}(x_i) are then compared with the same χp, 0.9752\chi^2_{p,\,0.975} cutoff. (Strictly, the reweighted covariance should also be inflated slightly, since it is fitted to points inside a 97.5% ellipse; scikit-learn skips this, R applies it.)

Worked example: 12 points, 3 outliers

Nine points rise from lower-left to upper-right (correlation +0.75+0.75). Three outliers sit together at the lower right. n=12n=12, p=2p=2, so h=⌊15/2⌋=7h=\lfloor 15/2\rfloor=7 and the cutoff is χ2, 0.9752=7.38\chi^2_{2,\,0.975}=7.38.

Pointx₁x₂Pointx₁x₂
P10.52P745
P221P84.54
P323P955
P42.52P1081
P534.5P1192
P64.53.5P1290
The data. P10–P12 are the planted outliers.

Classical fit. All 12 points give μ^=(4.50, 2.75)\hat\mu=(4.50,\,2.75) and Σ^=(7.33−1.35−1.352.56)\hat\Sigma=\begin{pmatrix}7.33&-1.35\\-1.35&2.56\end{pmatrix}, det⁡=16.96\det=16.96. Three outliers have flipped the sign of the correlation, from +0.75+0.75 to −0.31-0.31. The largest classical d2d^2 is P12's 4.354.35, well under 7.387.38: no point is flagged. P1, an ordinary inlier, has a larger distance (3.143.14) than outlier P10 (2.202.20).

StepSubset H (7 points)Outliers in Hμ_HΣ_H (σ₁₁, σ₁₂, σ₂₂)det Σ_H
H₀ (start J)P2, P5, P121(4.67, 1.83)(9.56, −3.39, 3.72)24.08
H₁P2, P3, P4, P6, P8, P10, P122(4.64, 2.07)(6.98, −1.80, 1.89)9.95
H₂P2, P3, P4, P5, P6, P8, P101(3.79, 2.71)(3.92, −0.53, 1.70)6.40
H₃P2, P3, P4, P5, P6, P7, P80(3.21, 3.29)(1.06, 0.90, 1.70)0.99
H₄P3, P4, P5, P6, P7, P8, P90(3.64, 3.86)(1.12, 0.70, 1.05)0.691
H₅= H₄ → converged0.691
C-steps by hand from start A, J = {P2, P5, P12} (one outlier among the 3 seeds). Each row: subset, its mean and covariance, and the determinant, which never goes up.

Check the theorem on step H1→H2H_1\to H_2: under the H1H_1 fit, the seven points chosen for H2H_2 have ∑d12=13.86≤hp=14\sum d_1^2=13.86\le hp=14; then tr⁡(Σ^1−1Σ^2)=1.75≤p=2\operatorname{tr}(\hat\Sigma_1^{-1}\hat\Sigma_2)=1.75\le p=2 and det⁡Σ^2/det⁡Σ^1=0.64≤(1.75/2)2=0.77\det\hat\Sigma_2/\det\hat\Sigma_1=0.64\le(1.75/2)^2=0.77. The outliers leave one at a time. Once the subset is clean, the ellipse snaps onto the inlier cloud, and the outliers' d2d^2 jump from single digits to 65–104.

StepSubset HOutliers in Hμ_Hdet Σ_H
H₀ (start J)P2, P8, P111(5.17, 2.33)12.68
H₁P2, P3, P4, P6, P8, P10, P112(4.64, 2.36)8.03
H₂P1, P3, P4, P6, P8, P10, P112(4.43, 2.50)7.11
H₃= H₂ → converged (local minimum)7.11
Start B, J = {P2, P8, P11}, gets trapped: it converges with two outliers still in the subset.

This is why FAST-MCD uses many starts: 0.691<7.110.691<7.11, so start A wins. Brute force over all (127)=792\binom{12}{7}=792 subsets confirms {P3,…,P9}\{P3,\dots,P9\} with det⁡=0.691\det=0.691 is the global MCD. Its raw covariance is (1.120.700.701.05)\begin{pmatrix}1.12&0.70\\0.70&1.05\end{pmatrix}.

Correction and reweighting

  1. 1Raw distances under H4H_4: inliers 0.900.90–8.828.82 (P1 = 8.82 and P2 = 7.87 are outside the subset and look extreme because the raw ellipse is too small), outliers 67.3, 69.4, 109.667.3,\ 69.4,\ 109.6.
  2. 2Consistency factor (median rule): the median of the 12 raw d2d^2 is 2.872.87, so c=2.87/1.386=2.07c=2.87/1.386=2.07. (The asymptotic formula would give c=0.583/P(χ42≤1.75)=2.67c=0.583/P(\chi^2_4\le1.75)=2.67.) Corrected distances: P1 4.264.26, P2 3.803.80; outliers 32.5, 33.5, 52.932.5,\ 33.5,\ 52.9.
  3. 3Weights: the 9 inliers are under 7.387.38, the 3 outliers are over it.
  4. 4Reweighted fit on the 9 inliers: μ^=(3.11, 3.33)\hat\mu=(3.11,\,3.33), Σ^=(1.991.441.441.83)\hat\Sigma=\begin{pmatrix}1.99&1.44\\1.44&1.83\end{pmatrix}, correlation +0.75+0.75, det⁡=1.58\det=1.58 (the classical one was 16.9616.96, so the 97.5% ellipse is 16.96/1.58≈3.3×\sqrt{16.96/1.58}\approx3.3\times smaller in area).
PointClassical d²Robust d² (final)Flag (robust)
P13.143.81
P22.973.56
P30.870.90
P41.091.19
P51.251.96
P60.241.85
P72.051.72
P80.681.11
P92.411.91
P102.2055.16outlier
P112.7656.59outlier
P124.3589.64outlier
Squared distances, classical vs robust (cutoff 7.38). The classical fit flags nothing; MCD flags exactly the three outliers. Values verified with numpy and sklearn.MinCovDet.
▸ FAST-MCD · 12 points, h = 7step 1/20
0246810120246123456789101112ellipses: d² = χ²₂(0.975) = 7.38 · dashed grey = classicaldet Σ per C-step (log scale)110classical 16.96H0H1H2H3H4
μ (4.50, 2.75)det Σ 16.96corr -0.31all n = 12 · outliers inside 3
  1. 1classical: μ, Σ ← mean, cov of all n
  2. 2for each random start J, |J| = p+1:
  3. 3 μ, Σ ← mean, cov of J
  4. 4 repeat: dᵢ² ← (xᵢ−μ)ᵀ Σ⁻¹ (xᵢ−μ)
  5. 5 H ← the h points with smallest dᵢ²
  6. 6 μ, Σ ← mean, cov of H # det ↓
  7. 7 until H stops changing
  8. 8keep the H with the smallest det Σ
  9. 9Σ ← Σ · median(d²) / χ²₂(0.5)
  10. 10w ← [d² ≤ χ²₂(0.975)]; refit on w

Classical fit on all 12 points. The 3 outliers drag the mean to (4.50, 2.75) and tilt the ellipse: correlation -0.31 although the bulk rises at +0.75. Largest d² is P12's 4.35 < 7.38, so nothing is flagged — masking.

▸ classical vs MCDdrag ● outliers or the ✛ cluster handle
- - classical 97.5%—— MCD 97.5%distance–distance plotmasked: only MCD flags0240714classical drobust d ↑ (cut √7.38 = 2.72)
n = 24 · h = 13 · contamination 17% · breakdown point 45.8%
correlation: classical -0.54 · MCD 0.78 · inliers alone 0.78
outliers flagged: classical 0/4 · MCD 4/4 · inliers flagged: 0 / 0
raw det Σ_H = 5.89e-6 · consistency × 2.81 · 41 starts
fig.Top: FAST-MCD on the worked example. Filled points are the current h-subset; the dashed contour is the old ellipse at the level of the 7th-smallest d² (everything inside it becomes the next subset); the det trace below only ever goes down. Start A sheds the outliers one by one; start B gets stuck with two of them; then the winner is consistency-corrected and reweighted. Bottom: drag the outlier cluster (✛) or single points and raise k. The classical ellipse (dashed) tilts toward the cluster and flags none of it; the MCD ellipse stays on the inliers until the outliers are about half the data (k = 20: contamination 50% exceeds the 47.5% breakdown point), when the cluster takes over the h-subset. The distance–distance plot puts masked points in the upper-left: small classical distance, large robust distance.

In code

python
1import numpy as np
2from scipy.stats import chi2
3
4X = np.array([[0.5, 2], [2, 1], [2, 3], [2.5, 2], [3, 4.5], [4.5, 3.5], [4, 5],
5 [4.5, 4], [5, 5], [8, 1], [9, 2], [9, 0]])
6n, p = X.shape
7h = (n + p + 1) // 2 # 7
8
9def fit(S):
10 mu = X[S].mean(axis=0)
11 cov = np.cov(X[S].T, bias=True) # divide by |S|, like sklearn
12 return mu, cov
13
14def mahal2(mu, cov):
15 D = X - mu
16 return np.einsum("ij,jk,ik->i", D, np.linalg.inv(cov), D)
17
18def c_steps(start, max_iter=100):
19 S = np.sort(start)
20 mu, cov = fit(S)
21 history = [(S, np.linalg.det(cov))]
22 for _ in range(max_iter):
23 d2 = mahal2(mu, cov)
24 S_new = np.sort(np.argsort(d2, kind="stable")[:h]) # h closest points
25 if np.array_equal(S_new, S):
26 break # fixed point
27 S = S_new
28 mu, cov = fit(S)
29 history.append((S, np.linalg.det(cov))) # det never increases
30 return S, mu, cov, history
31
32def fast_mcd(n_starts=200, seed=0):
33 rs = np.random.default_rng(seed)
34 best = None
35 for _ in range(n_starts):
36 J = rs.choice(n, size=p + 1, replace=False)
37 if np.linalg.det(fit(J)[1]) < 1e-12:
38 continue # collinear start
39 S, mu, cov, _ = c_steps(J)
40 if best is None or np.linalg.det(cov) < np.linalg.det(best[2]):
41 best = (S, mu, cov)
42 S, mu, cov = best
43 # consistency correction (sklearn's empirical median rule)
44 cov = cov * np.median(mahal2(mu, cov)) / chi2.ppf(0.5, p)
45 # reweighting at the 97.5% chi-square quantile
46 keep = mahal2(mu, cov) <= chi2.ppf(0.975, p)
47 mu, cov = fit(np.where(keep)[0])
48 return mu, cov, mahal2(mu, cov), S
49
50for S, d in c_steps([1, 4, 11])[3]: # start A = {P2, P5, P12}
51 print(S + 1, round(d, 4)) # dets 24.08, 9.95, 6.40, 0.99, 0.691
52
53mu, cov, d2, S = fast_mcd()
54print("raw subset", S + 1) # [3 4 5 6 7 8 9]
55print("mu", mu.round(3)) # [3.111 3.333]
56print("robust d2", d2.round(2)) # ... 55.16 56.59 89.64
FAST-MCD from scratch on the worked example: C-steps, random (p+1)-starts, consistency correction, reweighting.
python
1import numpy as np
2from scipy.stats import chi2
3from sklearn.covariance import EmpiricalCovariance, MinCovDet
4
5X = np.array([[0.5, 2], [2, 1], [2, 3], [2.5, 2], [3, 4.5], [4.5, 3.5], [4, 5],
6 [4.5, 4], [5, 5], [8, 1], [9, 2], [9, 0]])
7
8classical = EmpiricalCovariance().fit(X)
9mcd = MinCovDet(support_fraction=7 / 12, random_state=0).fit(X)
10
11print("raw support:", np.where(mcd.raw_support_)[0] + 1) # [3 4 5 6 7 8 9]
12print("raw location:", mcd.raw_location_.round(3)) # [3.643 3.857] (uncorrected)
13print("final location:", mcd.location_.round(3)) # [3.111 3.333] (reweighted)
14print("final covariance:\n", mcd.covariance_.round(3)) # [[1.988 1.435] [1.435 1.833]]
15
16cut = chi2.ppf(0.975, df=X.shape[1]) # 7.38
17d2_classical = classical.mahalanobis(X) # squared distances
18d2_robust = mcd.mahalanobis(X) # == mcd.dist_
19print("classical flags:", np.where(d2_classical > cut)[0] + 1) # []
20print("robust flags: ", np.where(d2_robust > cut)[0] + 1) # [10 11 12]
The same with scikit-learn. support_fraction = 7/12 reproduces h = 7; the default (h = 8 here) gives the same final answer on this data.

Use when

  • +The bulk of the data is roughly elliptical and you suspect contamination you can't describe in advance — MCD tolerates up to ~50% of it.
  • +Outliers may come in groups (a faulty sensor batch, a fraud ring): the masking that defeats classical distances is exactly what MCD handles.
  • +You need robust inputs for other methods: robust PCA, robust regression diagnostics, robust correlation matrices.
  • +Features are on different scales or correlated: MCD is affine equivariant, so no standardization is needed and correlations are respected.

Avoid when

  • −Dimension is high: you need h>ph>p and in practice n≳5pn\gtrsim 5p; FAST-MCD gets slow and unstable as pp grows past a few dozen. Use regularized variants (MRCD) or robust PCA first.
  • −The regular data are multimodal or curved (clusters, manifolds): a single ellipse is the wrong shape. Use LOF, Isolation Forest or a mixture model.
  • −Data are discrete or heavily tied: many h-subsets become singular (det = 0) and the minimum is meaningless.
  • −You need maximum efficiency on clean data: the raw MCD wastes almost half the sample (reweighting recovers much, not all).

Where it's used

Multivariate outlier detection

Robust Mahalanobis distances with a χ² cutoff in quality control, sensor monitoring and fraud screening; the engine of Elliptic Envelope.

Finance

Robust covariance matrices for portfolio risk, less distorted by crash days and data errors.

Chemometrics & spectroscopy

Robust PCA (ROBPCA) and robust calibration, where a few bad samples otherwise dominate the components.

Regression diagnostics

Distance–distance and robust leverage plots separate good leverage points from bad ones (MCD on the predictors).

Check yourself

Why did the classical Mahalanobis distance fail to flag P10–P12 in the worked example?

Check yourself

With n = 12, p = 2 and h = 7, what is the MCD's finite-sample breakdown point?

Check yourself

A C-step replaces subset H₁ by the 7 points closest under H₁'s fit. What can you guarantee about H₂?

Check yourself

Why is the raw MCD covariance multiplied by a consistency factor c > 1?

Remember

  • ✓Classical mean and covariance have a breakdown point of 1/n: a cluster of outliers inflates the ellipse and masks itself.
  • ✓MCD fits the h≈(n+p+1)/2h\approx(n+p+1)/2 points with the smallest covariance determinant, giving a breakdown point close to 50%.
  • ✓The C-step (refit, then keep the hh closest points) never increases det⁡Σ\det\Sigma. Proof: trace ≤p\le p, then AM–GM. It converges to a local minimum, so FAST-MCD uses many random starts.
  • ✓Raw MCD is too small: rescale it by a consistency factor (median rule: median⁡d2/χp,0.52\operatorname{median}d^2/\chi^2_{p,0.5}), then reweight with the points under χp,0.9752\chi^2_{p,0.975} to regain efficiency.
  • ✓Robust distances vs the χp2\chi^2_p cutoff expose outliers the classical distance hides. Compare the two in a distance–distance plot.
  • ✓Use it for elliptical, moderate-dimensional data. For high pp, multimodal or curved data, reach for regularized MCD, robust PCA, or non-parametric detectors.
← back to ML Algorithms roadmap