mojolearn.EllipticEnvelope#
- class mojolearn.EllipticEnvelope(*, store_precision=True, assume_centered=False, support_fraction=None, contamination=0.1, random_state=None, numeric_mode=None)[source]#
Bases:
MinCovDetOutlier detection for Gaussian-distributed data.
Follows scikit-learn’s
EllipticEnvelope: fits aMinCovDetand setsoffset_at thecontaminationpercentile 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)."identical"gives the same bits on NVIDIA and AMD GPUs;"fast"applies on Apple GPUs.
- Variables:
- Raises:
ValueError – If
contaminationis 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)
- __init__(*, store_precision=True, assume_centered=False, support_fraction=None, contamination=0.1, random_state=None, numeric_mode=None)[source]#
Methods
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.Return the negated squared Mahalanobis distance of each sample.
set_params(**params)Set constructor parameters by keyword.
- fit(X, y=None)[source]#
Fit the robust model and set
offset_.- Parameters:
X (array-like of shape (n_samples, n_features))
y (ignored)
- Returns:
self
- score_samples(X)[source]#
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)[source]#
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)[source]#
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)[source]#
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)[source]#
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:
ValueError – If y or sample_weight has a different length than X.
ZeroDivisionError – If the weights sum to zero.