Guides / QSAR and machine learning

metricsevaluationroc-auc

Evaluating a QSAR model with metrics that match the decision

RMSE, R², ROC-AUC, precision, recall and enrichment answer different questions. Learn which metric fits your decision and how to compute it.

Updated 4 min read

A good evaluation of a QSAR model starts from the decision the model will support. Use RMSE or MAE when you need the size of the error, a rank correlation when you need to order compounds, precision and recall when you will act on a flagged subset, and enrichment when you will pick the top of a ranked library. One headline number such as R² or accuracy is rarely enough.

Regression metrics

For a continuous endpoint, the main choices are these.

Beware the squared Pearson correlation. A model can have a high correlation between predicted and observed values and still be biased or scaled wrongly, so that every prediction is off by one log unit. Correlation does not see that, while RMSE does.

import numpy as np
from scipy.stats import spearmanr
from sklearn.metrics import mean_absolute_error, mean_squared_error, r2_score

def regression_report(y_true, y_pred):
    return {
        "MAE": mean_absolute_error(y_true, y_pred),
        "RMSE": mean_squared_error(y_true, y_pred) ** 0.5,
        "R2": r2_score(y_true, y_pred),
        "Spearman": spearmanr(y_true, y_pred)[0],
        "bias": float(np.mean(np.asarray(y_pred) - np.asarray(y_true))),
    }

Put the metrics next to a baseline. Predicting the training mean gives an R² near zero by definition, and a nearest-neighbour or ridge model gives a realistic floor. A result of 0.9 log units RMSE is hard to judge until you know the standard deviation of the endpoint and the experimental error. If repeat measurements of one compound differ by 0.5 log units, an RMSE of 0.6 is close to the ceiling.

Classification metrics

A confusion matrix has four counts: true positives, false positives, false negatives and true negatives. Everything else follows from them. Take a screen of 1000 compounds with 20 actives. The model flags 20 compounds, 12 of them truly active.

Precision and recall tell the story, and which one matters depends on cost. A safety filter wants high recall, since a missed toxic compound is expensive. A costly confirmatory assay wants high precision, since each false positive wastes money. The F1 score is their harmonic mean and the Matthews correlation coefficient uses all four counts and stays sensible on imbalanced data.

Ranking metrics for screening

When the model produces a score and you will take the top slice, threshold-free ranking metrics fit better.

from sklearn.metrics import average_precision_score, roc_auc_score

def enrichment(y_true, scores, fraction=0.01):
    n_top = max(1, int(len(scores) * fraction))
    order = np.argsort(scores)[::-1][:n_top]
    return (np.asarray(y_true)[order].mean()) / np.mean(y_true)

print(roc_auc_score(y_true, scores), average_precision_score(y_true, scores))
print(enrichment(y_true, scores, 0.01))

Report uncertainty, not a single number

A metric computed on 40 test compounds is noisy. Repeat the split with different seeds, or bootstrap the test set, and report the spread. Two models whose scores differ by less than that spread are not different. Compare candidates on the same folds, so that the difference is paired. A grouped split, as in the scaffold split explained, is also part of the evaluation, since a metric from a random split answers a different question.

Calibration matters when you use probabilities. A model that says 0.9 should be right about nine times in ten, and many tree ensembles are not calibrated out of the box. The reliability curve in scikit-learn shows this. Finally, tie the metric to a consequence. For a virtual screen, the useful statement is how many hits you expect in the 50 compounds you can test. The guide on building a screening cascade shows how model output feeds such a decision.

Key points

Questions people ask

Which metric should I use for a regression QSAR model?
Report RMSE or MAE in the units of the endpoint, because they tell you the typical error directly, and add a rank correlation such as Spearman if the model will be used to order compounds. R² alone hides the scale of the error.
Why is accuracy a bad metric for an imbalanced QSAR set?
If only 2 percent of compounds are active, a model that calls everything inactive is 98 percent accurate and finds nothing. Precision, recall, PR-AUC or enrichment reveal what accuracy hides.
What is the difference between ROC-AUC and PR-AUC?
ROC-AUC measures how well the model ranks a random active above a random inactive and is insensitive to class balance. PR-AUC focuses on the precision of the top-ranked compounds and drops sharply when actives are rare, which is why it matches screening decisions better.
What is an enrichment factor?
The enrichment factor at a given fraction is the hit rate in the top-ranked fraction divided by the hit rate in the whole set. An EF of 10 at 1 percent means the top 1 percent holds ten times more actives than random picking would.

Further reading

In practice: Advanced Modeling trains and applies QSAR models; the AI Foundry runs or fine-tunes ChemBERTa, MoLFormer-XL and Chemprop on a CSV, as a preview. Validation is the user's responsibility, and these guides show how.

← All guides