API CheatSheet

The following APIs are applicable for all detector models for ease of use.

  • pythresh.thresholders.base.BaseDetector.eval(): evaluate a single outlier or multiple outlier detection likelihood score set (Legacy method)

  • pythresh.thresholders.base.BaseDetector.fit(): fit a thresholder for a single outlier or multiple outlier detection likelihood score set

  • pythresh.thresholders.base.BaseDetector.predict(): predict the binary labels using the fitted thresholder on a single outlier or multiple outlier detection likelihood score set

Key Attributes of a fitted model:

  • pythresh.thresholds.base.BaseThresholder.thresh_: threshold value from scores normalize between 0 and 1

  • pythresh.thresholds.base.BaseThresholder.labels_: A binary array of labels for the fitted thresholder on the fitted dataset

  • pythresh.thresholders.base.BaseDetector.confidence_interval_: Return the lower and upper confidence interval of the contamination level. Only applies to the COMB thresholder

  • pythresh.thresholders.base.BaseDetector.dscores_: 1D array of the TruncatedSVD decomposed decision scores if multiple outlier detector score sets are passed

  • pythresh.thresholders.mixmod.MIXMOD.mixture_: fitted mixture model class of the selected model used for thresholding. Only applies to MIXMOD. Attributes include: components, weights, params. Functions include: fit, loglikelihood, pdf, and posterior.

See base class definition below:

pythresh.thresholds.base module

class pythresh.thresholds.base.BaseThresholder(fallback='warn')[source]

Bases: BaseEstimator

Abstract class for all outlier detection thresholding algorithms.

Parameters:

fallback (str ('ignore', 'warn', 'raise'), optional (default='warn')) – The action to take for thresholders when their criterion are not met. In these cases when set to ‘ignore’ on eval and fit all train data is set to inliers and the threshold is set to max of the train scores + eps. Passing ‘warn’ will do the same as ‘ignore’ but also produce a warning. If ‘raise’, the thresholder raises a ValueError.

thresh_
Type:

threshold value that separates inliers from outliers

labels_
Type:

binary array of labels for the fitted thresholder

confidence_interval_
Type:

lower and upper confidence interval of the contamination level

dscores_
Type:

1D array of decomposed decision scores

abstractmethod eval(decision)[source]

Outlier/inlier evaluation process for decision scores.

Parameters:

decision (np.array or list of shape (n_samples)) – or np.array of shape (n_samples, n_detectors) which are the decision scores from a outlier detection.

Returns:

outlier_labels – For each observation, tells whether or not it should be considered as an outlier according to the fitted model. 0 stands for inliers and 1 for outliers.

Return type:

numpy array of shape (n_samples,)

fit(X, y=None)[source]

Outlier/inlier fit process for decision scores.

Parameters:

decision (np.array or list of shape (n_samples)) – or np.array of shape (n_samples, n_detectors) which are the decision scores from a outlier detection.

get_metadata_routing()

Get metadata routing of this object.

Please check User Guide on how the routing mechanism works.

Returns:

routing – A MetadataRequest encapsulating routing information.

Return type:

MetadataRequest

get_params(deep=True)

Get parameters for this estimator.

Parameters:

deep (bool, default=True) – If True, will return the parameters for this estimator and contained subobjects that are estimators.

Returns:

params – Parameter names mapped to their values.

Return type:

dict

predict(X)[source]

Outlier/inlier predict process for decision scores.

Parameters:

decision (np.array or list of shape (n_samples)) – or np.array of shape (n_samples, n_detectors) which are the decision scores from a outlier detection.

Returns:

outlier_labels – For each observation, tells whether or not it should be considered as an outlier according to the fitted model. 0 stands for inliers and 1 for outliers.

Return type:

numpy array of shape (n_samples,)

set_params(**params)

Set the parameters of this estimator.

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

Parameters:

**params (dict) – Estimator parameters.

Returns:

self – Estimator instance.

Return type:

estimator instance