Regression versus classification in QSAR, and how to choose
Use regression when you have a continuous measurement and need ranking or magnitude, and classification for a yes or no decision. Here is how to pick.
Use regression when your data are continuous measurements such as pIC50 or log solubility and you need magnitude or ranking, and use classification when the real decision is yes or no or when the data are only available as classes or censored values. When in doubt, train on the continuous value and apply a threshold to the prediction afterwards.
What each one predicts
A regression model outputs a number: a predicted logS of -3.1, a predicted pIC50 of 6.8. A classification model outputs a class or a probability: soluble or insoluble, active or inactive, toxic with probability 0.7. The learning algorithms overlap heavily. A random forest, a gradient boosted tree and a neural network all come in both flavours, and the descriptor or fingerprint inputs are identical. What changes is the label, the loss function and the metrics, which are covered in evaluating a QSAR model.
Why the continuous label usually carries more
A measured value has a rank order and a size. Turning it into a class discards both. Suppose active means IC50 below 1 µM. A compound at 0.9 µM and one at 1.1 µM have almost the same potency and sit in different classes, and a compound at 0.9 µM and one at 0.001 µM share a class despite a thousandfold difference. Measurement error of a factor of two or three is normal for an IC50, so the labels near the boundary are close to coin flips.
A continuous endpoint should be placed on a sensible scale before modelling. Potencies span orders of magnitude, so take the negative logarithm. For an IC50 in nanomolar:
import numpy as np
import pandas as pd
df = pd.DataFrame({"ic50_nM": [3.0, 120.0, 4500.0]})
df["pic50"] = 9 - np.log10(df["ic50_nM"])
print(df)
The factor 9 comes from converting nanomolar to molar, since pIC50 equals minus the log of the molar value. The guide on IC50, Ki, EC50 and Kd explains what the underlying quantities mean and why they are not interchangeable. Mixing them in one regression adds hidden noise.
When classification is the right tool
- The decision is binary. A safety flag such as a hERG liability screen, an Ames mutagenicity call or a go or no-go on a permeability cut-off is a classification question, and the cost of errors may be asymmetric.
- The data are censored. Entries like "greater than 10 µM" or "less than 0.1 nM" are not numbers. Dropping them biases the data, and keeping them as exact numbers is wrong, but as class labels they are fine.
- The assay is qualitative. Many screening outputs are hit or non-hit.
- The labels come from different assays. If values cannot be put on one scale, an agreed class definition may be the only common ground.
Class imbalance is the main trap. Hits are rare, often a few percent, so accuracy is misleading and a model that predicts "inactive" for everything looks excellent. Use balanced class weights or resampling during training and judge with precision, recall and PR-AUC, not accuracy.
Choosing the threshold
If you must classify, choose the threshold from the decision, not from habit. A threshold of 10 µM may suit a primary screen and 100 nM a lead-optimisation stage. For solubility, a cut at logS of -4 is common as an illustration of a poorly soluble compound, but the right cut depends on dose and formulation. Avoid creating a third "intermediate" class by dropping compounds near the boundary and then reporting performance on the easy remainder, since that inflates the score.
A useful pattern is to train a regressor, then evaluate it as a classifier at several thresholds, as below.
from sklearn.ensemble import RandomForestRegressor
from sklearn.metrics import roc_auc_score
from sklearn.model_selection import cross_val_predict
pred = cross_val_predict(RandomForestRegressor(n_estimators=300, random_state=0), X, y, cv=5)
for cut in (-5, -4, -3):
print(cut, roc_auc_score(y > cut, pred))
This shows how performance changes with the cut-off and tells you whether the model ranks well near the boundary you care about. The predicted value serves as the score, so no classifier needs training.
Ordinal and multi-class cases
Between the two sits ordinal classification, with classes such as low, medium and high clearance. Treat it as regression on a rank, or as a classifier with an ordered loss, rather than as unordered categories, because predicting "high" when the truth is "low" should cost more than predicting "medium".
Whatever the task, keep the split honest, using a grouped scheme such as in train and test splits in chemistry. A different kind of score, such as a docking score, is not an affinity either, and treating it as a continuous label has its own pitfalls, as discussed in why docking scores are not binding affinities.
A small decision rule
Ask three questions. Is most of my data a real number or a bound such as "greater than"? Will the next step be a ranking of compounds or a yes or no gate? How noisy is the assay compared with the range of values? Real numbers, ranking and a modest noise level point to regression. Bounds, a hard gate or a very noisy assay point to classification. If the answers disagree, train the regressor, threshold its output, and check whether a classifier trained on the labels does any better on the same grouped split.
Key points
- Regression keeps rank and magnitude. Classification answers a binary decision and handles censored or qualitative data.
- Convert potencies to pIC50 before regression, using 9 minus log10 of the nanomolar value.
- Thresholding noisy values makes noisy labels near the boundary.
- A regressor evaluated at several thresholds is often better than a classifier trained on one threshold.
- With rare actives, use precision, recall and PR-AUC, not accuracy.
Questions people ask
- Should I treat IC50 data as regression or classification?
- If you have measured values for most compounds, convert them to pIC50 and use regression, because it keeps more information. Use classification when many values are censored, such as greater than 10 micromolar, or when the real decision is a binary go or no-go.
- What is pIC50?
- pIC50 is the negative base-10 logarithm of the IC50 expressed in molar units. An IC50 of 100 nM is 10 to the power of minus 7 molar, so its pIC50 is 7.
- Why is thresholding a continuous value risky?
- Compounds near the threshold flip class because of ordinary experimental error, so the classification boundary is noisier than the measurement itself. A model then has to learn labels that are partly random.
- Can I convert a regression model into a classifier?
- Yes. Predict the value and apply the threshold afterwards. This often works better than training a classifier on thresholded labels, because the model sees the full information during training.
Further reading
- scikit-learn documentation, supervised learning
- Wu et al., MoleculeNet, a benchmark for molecular machine learning (2018)
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.