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.
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.
- MAE, mean absolute error, the average size of the miss. A few large errors move it little, and it is in the endpoint's units.
- RMSE, root mean squared error, which punishes large misses more. It is also in the endpoint's units and is the natural scale for a statement such as "predictions are typically within 0.8 log units".
- R², the fraction of variance explained. In scikit-learn it is one minus the ratio of residual to total variance, so it can be negative when the model is worse than predicting the mean. It depends on the spread of the test set, so the same model has a higher R² on a wider range of values.
- Spearman rank correlation, which asks whether the order is right and ignores scale. Use it when the model ranks compounds for selection.
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.
- True positives 12, false positives 8, false negatives 8, true negatives 972.
- Accuracy is (12 + 972) / 1000 = 0.984, which looks excellent, but a model that predicts "inactive" for all would score 0.98.
- Precision is 12 / 20 = 0.60, the share of flagged compounds that are real.
- Recall is 12 / 20 = 0.60, the share of real actives found.
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.
- ROC-AUC is the probability that a random active scores above a random inactive. It ignores class balance, so it can look good while the top of the list is full of false positives.
- PR-AUC, the area under the precision-recall curve, is sensitive to rare actives and follows the screening experience more closely.
- The enrichment factor at x percent is the hit rate in the top x percent divided by the overall hit rate. In the example above, if the top 10 compounds, 1 percent of the set, hold 6 actives, the hit rate is 0.6 against a base of 0.02, so the enrichment factor is 30.
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
- Pick the metric from the decision. Magnitude calls for RMSE or MAE, ordering for Spearman, flagged subsets for precision and recall, top-slice picking for PR-AUC and enrichment.
- R² depends on the spread of the data and can be negative. Always compare with a baseline.
- Accuracy is misleading when actives are rare.
- Report the spread over repeated splits and paired comparisons between models.
- Check calibration if you use predicted probabilities.
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
- scikit-learn documentation, metrics and scoring
- Tropsha, Best practices for QSAR model development, validation and exploitation (2010)
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.