ProbStdADChecker#
- class skfp.applicability_domain.ProbStdADChecker(model: object | None = None, threshold: float = 0.1, n_jobs: int | None = None, verbose: int | dict = 0)#
Probabilistic standard deviation method (PROB-STD).
Defines applicability domain based on the probabilistic interpretation of prediction uncertainty from individual estimators in an ensemble model [1]. For each sample, the mean and standard deviation of the ensemble predictions are used to construct a normal distribution. The score is defined as the probability mass under this distribution that lies on the wrong side of the classification threshold (0.5).
This approach supports both regression models (using
.predict(X)) and binary classifiers (using.predict_proba(X)and the probability of the positive class). For regression models, the outputs should be interpretable as positive-class probabilities in [0, 1], e.g. when the regressor is trained on binary targets. The ensemble model must expose theestimators_attribute. If no model is provided, a defaultRandomForestRegressoris created and trained duringfit().At prediction time, each sample is passed to all estimators, and their predictions (or predicted probabilities for classifiers) are used to construct the distribution. The sample is considered in-domain if the resulting probability of misclassification (PROB-STD) is lower than or equal to the specified threshold.
- Parameters:
model (object, default=None) – Fitted ensemble model with accessible
estimators_attribute and either.predict(X)or.predict_proba(X)method on each sub-estimator. If not provided, a defaultRandomForestRegressorwill be created. Note that if you pass a fitted model here, call tofit()is not necessary, but it will perform model validation.threshold (float, default=0.1) – Maximum allowed probability of incorrect class assignment. Lower values yield a stricter applicability domain.
n_jobs (int, default=None) – The number of jobs to run in parallel.
transform_x_y()andtransform()are parallelized over the input molecules.Nonemeans 1 unless in ajoblib.parallel_backendcontext.-1means using all processors. See scikit-learn documentation onn_jobsfor 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 sklearn.ensemble import RandomForestRegressor >>> from skfp.applicability_domain import ProbStdADChecker >>> X_train = np.random.uniform(0, 1, size=(1000, 5)) >>> y_train = (X_train[:, 0] + X_train[:, 1] > 1).astype(float) >>> model = RandomForestRegressor(n_estimators=10, random_state=0) >>> model.fit(X_train, y_train) >>> probstd_ad_checker = ProbStdADChecker(model=model, threshold=0.1) >>> probstd_ad_checker.fit() >>> probstd_ad_checker ProbStdADChecker(model=RandomForestRegressor(...), threshold=0.1)
>>> X_test = np.random.uniform(0, 1, size=(100, 5)) >>> probstd_ad_checker.predict(X_test).shape (100,)
Methods
fit([X, y])Fit applicability domain estimator.
fit_predict(X[, y])Perform fit on X and returns labels for X.
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.
Calculate the applicability domain score of samples.
set_params(**params)Set the parameters of this estimator.
- fit(X: ndarray | None = None, 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
MetadataRequestencapsulating 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) 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 defined as the minimum probabilistic mass under the normal distribution that lies on either side of the classification threshold (0.5). Lower values indicate higher confidence in class assignment.
- Parameters:
X (array-like of shape (n_samples, n_features)) – The data matrix.
- Returns:
scores – Probabilistic scores reflecting the uncertainty of class assignment.
- 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