This documentation is for scikit-learn version 0.11-gitOther versions

Citing

If you use the software, please consider citing scikit-learn.

This page

8.2.7. sklearn.covariance.MinCovDet

class sklearn.covariance.MinCovDet(store_precision=True, assume_centered=False, support_fraction=None, random_state=None)

Minimum Covariance Determinant (MCD): robust estimator of covariance

Parameters :

store_precision: bool :

Specify if the estimated precision is stored

assume_centered: Boolean :

If True, the support of robust location and covariance estimates is computed, and a covariance estimate is recomputed from it, without centering the data. Useful to work with data whose mean is significantly equal to zero but is not exactly zero. If False, the robust location and covariance are directly computed with the FastMCD algorithm without additional treatment.

support_fraction: float, 0 < support_fraction < 1 :

The proportion of points to be included in the support of the raw MCD estimate. Default is None, which implies that the minimum value of support_fraction will be used within the algorithm: [n_sample + n_features + 1] / 2

random_state: integer or numpy.RandomState, optional :

The random generator used. If an integer is given, it fixes the seed. Defaults to the global numpy random number generator.

Notes

References:

[Rouseeuw1984](1, 2) P. J. Rousseeuw. Least median of squares regression. J. Am Stat Ass, 79:871, 1984.
[Rouseeuw1999]A Fast Algorithm for the Minimum Covariance Determinant Estimator, 1999, American Statistical Association and the American Society for Quality, TECHNOMETRICS
[Butler1993]R. W. Butler, P. L. Davies and M. Jhun, Asymptotics For The Minimum Covariance Determinant Estimator, The Annals of Statistics, 1993, Vol. 21, No. 3, 1385-1400

Attributes

raw_location_: array-like, shape (n_features,) The raw robust estimated location before correction and reweighting
raw_covariance_: array-like, shape (n_features, n_features) The raw robust estimated covariance before correction and reweighting
raw_support_: array-like, shape (n_samples,) A mask of the observations that have been used to compute the raw robust estimates of location and shape, before correction and reweighting.
location_: array-like, shape (n_features,) Estimated robust location
covariance_: array-like, shape (n_features, n_features) Estimated robust covariance matrix
precision_: array-like, shape (n_features, n_features) Estimated pseudo inverse matrix. (stored only if store_precision is True)
support_: array-like, shape (n_samples,) A mask of the observations that have been used to compute the robust estimates of location and shape.

Methods

correct_covariance(data) Apply a correction to raw Minimum Covariance Determinant estimates.
error_norm(comp_cov[, norm, scaling, squared]) Computes the Mean Squared Error between two covariance estimators.
fit(X) Fits a Minimum Covariance Determinant with the FastMCD algorithm.
mahalanobis(observations) Computes the mahalanobis distances of given observations.
reweight_covariance(data) Reweight raw Minimum Covariance Determinant estimates.
score(X_test[, assume_centered]) Computes the log-likelihood of a gaussian data set with self.covariance_ as an estimator of its covariance matrix.
set_params(**params) Set the parameters of the estimator.
__init__(store_precision=True, assume_centered=False, support_fraction=None, random_state=None)
correct_covariance(data)

Apply a correction to raw Minimum Covariance Determinant estimates.

Correction using the empirical correction factor suggested by Rousseeuw and Van Driessen in [Rouseeuw1984].

Parameters :

data: array-like, shape (n_samples, n_features) :

The data matrix, with p features and n samples. The data set must be the one which was used to compute the raw estimates.

Returns :

covariance_corrected: array-like, shape (n_features, n_features) :

Corrected robust covariance estimate.

error_norm(comp_cov, norm='frobenius', scaling=True, squared=True)

Computes the Mean Squared Error between two covariance estimators. (In the sense of the Frobenius norm)

Parameters :

comp_cov: array-like, shape = [n_features, n_features] :

The covariance to compare with.

norm: str :

The type of norm used to compute the error. Available error types: - ‘frobenius’ (default): sqrt(tr(A^t.A)) - ‘spectral’: sqrt(max(eigenvalues(A^t.A)) where A is the error (comp_cov - self.covariance_).

scaling: bool :

If True (default), the squared error norm is divided by n_features. If False, the squared error norm is not rescaled.

squared: bool :

Whether to compute the squared error norm or the error norm. If True (default), the squared error norm is returned. If False, the error norm is returned.

Returns :

The Mean Squared Error (in the sense of the Frobenius norm) between :

`self` and `comp_cov` covariance estimators. :

fit(X)

Fits a Minimum Covariance Determinant with the FastMCD algorithm.

Parameters :

X: array-like, shape = [n_samples, n_features] :

Training data, where n_samples is the number of samples and n_features is the number of features.

Returns :

self: object :

Returns self.

mahalanobis(observations)

Computes the mahalanobis distances of given observations.

The provided observations are assumed to be centered. One may want to center them using a location estimate first.

Parameters :

observations: array-like, shape = [n_observations, n_features] :

The observations, the Mahalanobis distances of the which we compute.

Returns :

mahalanobis_distance: array, shape = [n_observations,] :

Mahalanobis distances of the observations.

reweight_covariance(data)

Reweight raw Minimum Covariance Determinant estimates.

Reweight observations using Rousseeuw’s method (equivalent to deleting outlying observations from the data set before computing location and covariance estimates). [Rouseeuw1984]

Parameters :

data: array-like, shape (n_samples, n_features) :

The data matrix, with p features and n samples. The data set must be the one which was used to compute the raw estimates.

Returns :

location_reweighted: array-like, shape (n_features, ) :

Reweighted robust location estimate.

covariance_reweighted: array-like, shape (n_features, n_features) :

Reweighted robust covariance estimate.

support_reweighted: array-like, type boolean, shape (n_samples,) :

A mask of the observations that have been used to compute the reweighted robust location and covariance estimates.

score(X_test, assume_centered=False)

Computes the log-likelihood of a gaussian data set with self.covariance_ as an estimator of its covariance matrix.

Parameters :

X_test : array-like, shape = [n_samples, n_features]

Test data of which we compute the likelihood, where n_samples is the number of samples and n_features is the number of features.

Returns :

res : float

The likelihood of the data set with self.covariance_ as an estimator of its covariance matrix.

set_params(**params)

Set the parameters of the estimator.

The method works on simple estimators as well as on nested objects (such as pipelines). The former have parameters of the form <component>__<parameter> so that it’s possible to update each component of a nested object.

Returns :self :