Skip to content

API reference

The names below are available directly from the qsarcert package.

Functions

qsarcert.calculate_applicability_domain(x_train, x_eval, y_true, y_pred, y_train_residuals=None, residual_threshold=3.0, min_pass_pct_in_domain=85.0, min_warn_pct_in_domain=70.0)

Computes leverages h_i = x_i (X^T X)^+ x_i^T of the evaluated compounds with respect to the training design (standardised descriptors plus intercept), the warning leverage h*, standardised residuals and the Williams plot categories.

Parameters:

Name Type Description Default
x_train ndarray

Descriptor matrices (n, p) used by the model.

required
x_eval ndarray

Descriptor matrices (n, p) used by the model.

required
y_true ndarray

Observed and predicted responses of the evaluated compounds (Williams plot only).

required
y_pred ndarray

Observed and predicted responses of the evaluated compounds (Williams plot only).

required
y_train_residuals ndarray

Training residuals. Their standard deviation (n - p - 1 degrees of freedom) is the residual scale s, as in the Williams plot. Without them a robust scale of the evaluated residuals is used and reported as such.

None
residual_threshold float
3.0
min_pass_pct_in_domain float

Coverage (percentage with h <= h*) for PASS and WARNING.

85.0
min_warn_pct_in_domain float

Coverage (percentage with h <= h*) for PASS and WARNING.

85.0
Notes

Leverage bounds the domain only when the design has many more compounds than descriptors. When h* >= 1 (3(p + 1) >= n) every training compound is below h* by construction (training leverages cannot exceed 1), the threshold no longer describes the training data and the status is NOT_APPLICABLE; reduce the descriptors (e.g. to those of the model or to principal components) or use a distance-based domain.

qsarcert.calculate_oecd_metrics(y_true, y_pred, y_train_mean=None, min_pass_q2=0.6, min_warn_q2=0.5, y_train=None)

Computes all standard OECD & Tropsha-Golbraikh QSAR validation metrics.

Parameters:

Name Type Description Default
y_true ndarray

Observed experimental values.

required
y_pred ndarray

Model predicted values.

required
y_train_mean float

Mean of the training set (used for Q2_F1). Taken from y_train when that is given.

None
y_train ndarray

Training responses. Needed for Q2_F1 (training mean) and Q2_F3 (training variance); without it Q2_F1 falls back to the evaluation mean (= Q2_F2) and Q2_F3 is NaN.

None
Notes

Definitions follow Consonni, Ballabio & Todeschini (2009) for Q2_F1/F2/F3, Lin (1989) for CCC, Golbraikh & Tropsha (2002) and Roy et al. (2012) for the regression-through-origin criteria, where r^2 is the squared Pearson correlation between observed and predicted values. min_pass_q2 : float, default 0.60 min_warn_q2 : float, default 0.50

Returns:

Name Type Description
result OECDValidationResult

qsarcert.perform_y_randomization(x_features, y_true, original_r2=None, n_iterations=100, random_seed=42, estimator=None, cv_folds=5)

Executes the Y-randomization test by permuting the responses n_iterations times.

Parameters:

Name Type Description Default
x_features ndarray

Training descriptor matrix (n_samples, n_features).

required
y_true ndarray

Training responses.

required
original_r2 float

Ignored; kept for backward compatibility. The reference R^2 is always recomputed with the same procedure as the permuted ones, so that cR^2_p compares like with like.

None
n_iterations int
100
random_seed int
42
estimator object with fit/predict

The user's model. When given, the original and permuted responses are scored by k-fold cross-validated R^2 of this model instead of the OLS surrogate.

None
cv_folds int
5

Returns:

Name Type Description
result YRandomizationResult

qsarcert.check_split_leakage(x_train, x_test, similarity_threshold=0.95, smiles_train=None, smiles_test=None)

Evaluates duplicated inputs and extreme similarity between the training and test sets.

Parameters:

Name Type Description Default
x_train ndarray

Feature matrices used by the model.

required
x_test ndarray

Feature matrices used by the model.

required
similarity_threshold float
0.95
smiles_train sequence of str

Structures, for duplicate-structure and scaffold checks (requires RDKit).

None
smiles_test sequence of str

Structures, for duplicate-structure and scaffold checks (requires RDKit).

None

qsarcert.assess_qsar_quality(metadata, y_true, y_pred, x_train=None, x_eval=None, y_train=None, run_y_scrambling=True, n_scrambling_iterations=100, y_train_pred=None, estimator=None, smiles_train=None, smiles_eval=None)

Evaluates QSAR & Molecular ML model against OECD Validation Principles.

Parameters:

Name Type Description Default
metadata dict

Endpoint (e.g. pIC50, LogP, Toxicity), algorithm (e.g. Random Forest, XGBoost, GNN), descriptor type.

required
y_true ndarray

Observed experimental values (evaluated/test set).

required
y_pred ndarray

Model predicted values (evaluated/test set).

required
x_train ndarray

Training feature matrix for applicability domain & Y-randomization.

None
x_eval ndarray

Evaluation/test feature matrix for applicability domain.

None
y_train ndarray

Training target vector for Y-randomization.

None
run_y_scrambling bool
True
n_scrambling_iterations int
100
y_train_pred ndarray

Training predictions; the training residuals give the residual scale of the Williams plot.

None
estimator object with fit/predict

The model, refitted on permuted responses for Y-randomization (cross-validated R^2). Without it an OLS surrogate is used, which is valid only for few descriptors.

None
smiles_train list of str

Structures for the duplicate-structure and scaffold checks (requires RDKit).

None
smiles_eval list of str

Structures for the duplicate-structure and scaffold checks (requires RDKit).

None

Returns:

Name Type Description
report QSARValidationReport

Result classes

qsarcert.ApplicabilityDomainResult dataclass

qsarcert.OECDValidationResult dataclass

qsarcert.YRandomizationResult dataclass

qsarcert.SplitLeakageResult dataclass

qsarcert.QSARValidationReport dataclass