DistanceToCentroidADChecker#

class skfp.applicability_domain.DistanceToCentroidADChecker(threshold: float | str = 'auto', metric: str | Callable = 'euclidean', n_jobs: int | None = None, verbose: int | dict = 0)#

Distance to centroid method.

Defines applicability domain based on range from the point to the training data centroid, i.e. the average (middle) point [1]. New molecules should lie inside the hypersphere of a given radius (distance) from that centroid.

Typically, physicochemical properties (continous features) are used as inputs. Consider scaling, normalizing, or transforming them before computing AD to lessen effects of outliers, e.g. with PowerTransformer or RobustScaler.

Note that as this method directly uses distances between points, it is highly recommended to scale the features to have the same value range. Having too high dimensionality, particularly with Euclidean distance, may deteriorate performance due to the curse of dimensionality.

This method scales very well with number of samples, but high number of features risks adverse effects of the curse of dimensionality for many metrics.

Parameters:
  • threshold (float or "auto", default="auto") – Maximal distance allowed for applicability domain. New points with larger leverage, i.e. distance to training set, are assumed to lie outside AD. "auto" calculates the distribution of data-centroid distances from the training data and uses its 99th percentile.

  • metric (str or callable, default="euclidean") – Metric to use for distance computation. Default is Euclidean distance. You can use any scikit-fingerprints distance for vectors here, but using bulk variants will be faster. Strings are mapped to functions for two vectors, for binary vectors if both binary and count variants are available, e.g. “tanimoto” maps to tanimoto_binary_distance.

  • n_jobs (int, default=None) – The number of jobs to run in parallel. transform_x_y() and transform() are parallelized over the input molecules. None means 1 unless in a joblib.parallel_backend context. -1 means using all processors. See scikit-learn documentation on n_jobs for more details.

  • verbose (int or dict, default=0) – Controls the verbosity when filtering molecules. If a dictionary is passed, it is treated as kwargs for tqdm(), and can be used to control the progress bar.

References

Examples

>>> import numpy as np
>>> from skfp.applicability_domain import DistanceToCentroidADChecker
>>> X_train = np.array([[0.0, 1.0], [0.0, 3.0], [3.0, 1.0]])
>>> X_test = np.array([[1.0, 1.0], [1.0, 2.0], [20.0, 3.0]])
>>> centroid_dist_ad_checker = DistanceToCentroidADChecker()
>>> centroid_dist_ad_checker
DistanceToCentroidADChecker()
>>> centroid_dist_ad_checker.fit(X_train)
DistanceToCentroidADChecker()
>>> centroid_dist_ad_checker.predict(X_test)
array([ True,  True, False])

Methods

fit(X[, y])

Fit applicability domain estimator.

fit_predict(X[, y])

Perform fit on X and returns labels for X.

get_metadata_routing()

Get metadata routing of this object.

get_params([deep])

Get parameters for this estimator.

predict(X)

Predict labels (1 inside AD, 0 outside AD) of X according to fitted model.

score_samples(X)

Calculate the applicability domain score of samples.

set_params(**params)

Set the parameters of this estimator.

fit(X: ndarray, y: ndarray | None = None)#

Fit applicability domain estimator.

Parameters:
  • X (array-like of shape (n_samples, n_features)) – The input samples.

  • y (any) – Unused, kept for scikit-learn compatibility.

Returns:

self – Fitted estimator.

Return type:

object

fit_predict(X, y=None, **kwargs)#

Perform fit on X and returns labels for X.

Returns -1 for outliers and 1 for inliers.

Parameters:
  • X ({array-like, sparse matrix} of shape (n_samples, n_features)) – The input samples.

  • y (Ignored) – Not used, present for API consistency by convention.

  • **kwargs (dict) –

    Arguments to be passed to fit.

    Added in version 1.4.

Returns:

y – 1 for inliers, -1 for outliers.

Return type:

ndarray of shape (n_samples,)

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: ndarray | csr_array) ndarray#

Predict labels (1 inside AD, 0 outside AD) of X according to fitted model.

Parameters:

X (array-like of shape (n_samples, n_features)) – The data matrix.

Returns:

is_inside_applicability_domain – Returns 1 for molecules inside applicability domain, and 0 for those outside (outliers).

Return type:

ndarray of shape (n_samples,)

score_samples(X: ndarray) ndarray#

Calculate the applicability domain score of samples. It is equal to the distance of each sample to the training data centroid. Note that here lower score indicates sample more firmly inside AD.

Parameters:

X (array-like of shape (n_samples, n_features)) – The data matrix.

Returns:

scores – Applicability domain scores of samples.

Return type:

ndarray 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