mojolearn.EllipticEnvelope#

class mojolearn.EllipticEnvelope(*, store_precision=True, assume_centered=False, support_fraction=None, contamination=0.1, random_state=None, numeric_mode=None)#

Outlier detection for Gaussian-distributed data.

Follows scikit-learn’s EllipticEnvelope: fits a MinCovDet and sets offset_ at the contamination percentile of the negated training distances, so that about that fraction of training points is labeled an outlier.

Parameters:
  • store_precision (bool, default True) – Store precision_.

  • assume_centered (bool, default False) – Treat the data as centered.

  • support_fraction (float or None, default None) – Fraction of points in the raw support; see MinCovDet.

  • contamination (float, default 0.1) – Expected fraction of outliers, in (0, 0.5].

  • 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). In identical mode, mojolearn returns the same bits on Apple, NVIDIA and AMD GPUs. "fast" is available on Apple GPUs only.

Variables:
  • offset_ (float) – Threshold on the decision function.

  • dist_ (location_, covariance_, precision_, support_,) – As in MinCovDet.

Raises:

ValueError – If contamination is not in (0, 0.5].

Examples

>>> import numpy as np, mojolearn
>>> X = np.random.default_rng(0).normal(size=(500, 3)).astype(np.float32)
>>> labels = mojolearn.EllipticEnvelope(contamination=0.05, random_state=0).fit(X).predict(X)

Methods

decision_function(X)

Return score_samples(X) - offset_; negative means outlier.

fit(X[, y])

Fit the robust model and set offset_.

fit_predict(X[, y])

Fit the model, then return predict(X).

fit_transform(X[, y])

Fit to X, then return transform(X).

get_params([deep])

Return this estimator's constructor parameters.

get_precision()

Return the precision matrix (pseudo-inverse of covariance_).

mahalanobis(X)

Return squared Mahalanobis distances under the fitted model.

predict(X)

Label each sample 1 (inlier) or -1 (outlier).

score(X, y[, sample_weight])

Return the accuracy of predict(X) against labels y.

score_samples(X)

Return the negated squared Mahalanobis distance of each sample.

set_params(**params)

Set constructor parameters by keyword.

fit(X, y=None)#

Fit the robust model and set offset_.

Parameters:
  • X (array-like of shape (n_samples, n_features))

  • y (ignored)

Returns:

self

score_samples(X)#

Return the negated squared Mahalanobis distance of each sample.

Parameters:

X (array-like of shape (n_samples, n_features))

Returns:

ndarray of shape (n_samples,), float32

decision_function(X)#

Return score_samples(X) - offset_; negative means outlier.

Parameters:

X (array-like of shape (n_samples, n_features))

Returns:

ndarray of shape (n_samples,), float32

predict(X)#

Label each sample 1 (inlier) or -1 (outlier).

Parameters:

X (array-like of shape (n_samples, n_features))

Returns:

ndarray of shape (n_samples,), int32

fit_predict(X, y=None)#

Fit the model, then return predict(X).

Parameters:
  • X (array-like of shape (n_samples, n_features))

  • y (ignored)

Returns:

ndarray of shape (n_samples,), int32

score(X, y, sample_weight=None)#

Return the accuracy of predict(X) against labels y.

As scikit-learn’s EllipticEnvelope.score: the (weighted) fraction of exact label matches.

Parameters:
  • X (array-like of shape (n_samples, n_features))

  • y (array-like of shape (n_samples,)) – True labels (1 inlier, -1 outlier).

  • sample_weight (array-like of shape (n_samples,) or None, default None)

Returns:

float

Raises:
fit_transform(X, y=None)#

Fit to X, then return transform(X).

Parameters:
  • X (array-like of shape (n_samples, n_features)) – Training data.

  • y (ignored)

Returns:

ndarray of shape (n_samples, n_components), float32

get_params(deep=True)#

Return this estimator’s constructor parameters.

Parameters:

deep (bool, default True) – Accepted for scikit-learn compatibility; it has no effect.

Returns:

dict – Parameter name to current value.

get_precision()#

Return the precision matrix (pseudo-inverse of covariance_).

Available even when store_precision=False.

Returns:

ndarray of shape (n_features, n_features), float32

mahalanobis(X)#

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.

set_params(**params)#

Set constructor parameters by keyword.

Raises:

ValueError – If a keyword is not a parameter of this estimator.

Returns:

self