mojolearn.MinCovDet#
- class mojolearn.MinCovDet(*, store_precision=True, assume_centered=False, support_fraction=None, random_state=None, numeric_mode=None)[source]#
Bases:
_BaseMinimum covariance determinant: a robust covariance estimator.
Follows scikit-learn’s
MinCovDet(FastMCD), including the consistency correction and the reweighting step. Random subsets come from mojolearn’s own generator and ties are broken by row index, so results can differ from scikit-learn’s for the same seed.- Parameters:
store_precision (bool, default True) – Store
precision_; when False it is None.assume_centered (bool, default False) – Treat the data as centered (location fixed at zero).
support_fraction (float or None, default None) – Fraction of points in the raw support. None uses
ceil((n_samples + n_features + 1) / 2)points.random_state (int or None, default None) – Seed for the random subsets; None means 0.
numeric_mode ({“identical”, “fast”} or None, default None) – Numeric mode for this estimator. None uses the package default (
"identical"unless changed)."identical"gives the same bits on NVIDIA and AMD GPUs;"fast"applies on Apple GPUs.
- Variables:
location_ (ndarray of shape (n_features,)) – Robust location (reweighted).
covariance_ (ndarray of shape (n_features, n_features)) – Robust covariance (reweighted).
precision_ (ndarray of shape (n_features, n_features) or None)
support_ (ndarray of shape (n_samples,), uint8) – 1 for points used in the reweighted estimate.
raw_location_ (ndarray of shape (n_features,))
raw_covariance_ (ndarray of shape (n_features, n_features))
raw_support_ (ndarray of shape (n_samples,), uint8)
dist_ (ndarray of shape (n_samples,)) – Squared Mahalanobis distances of the training points.
n_features_in_ (int)
Examples
>>> import numpy as np, mojolearn >>> X = np.random.default_rng(0).normal(size=(500, 3)).astype(np.float32) >>> mcd = mojolearn.MinCovDet(random_state=0).fit(X) >>> d = mcd.mahalanobis(X)
- __init__(*, store_precision=True, assume_centered=False, support_fraction=None, random_state=None, numeric_mode=None)[source]#
Methods
fit(X[, y])Fit the robust location and covariance.
fit_transform(X[, y])Fit to X, then return
transform(X).get_params([deep])Return this estimator's constructor parameters.
Return the precision matrix (pseudo-inverse of
covariance_).mahalanobis(X)Return squared Mahalanobis distances under the fitted model.
score(X[, y])Return the Gaussian log-likelihood of X under the fitted model.
set_params(**params)Set constructor parameters by keyword.
- fit(X, y=None)[source]#
Fit the robust location and covariance.
- Parameters:
X (array-like of shape (n_samples, n_features))
y (ignored)
- Returns:
self
- mahalanobis(X)[source]#
Return squared Mahalanobis distances under the fitted model.
- Parameters:
X (array-like of shape (n_samples, n_features))
- Returns:
ndarray of shape (n_samples,), float32
- Raises:
RuntimeError – If the model is not fitted.