Overview

3 Ligand-based Screening: Machine Learning

In this chapter, the machine learning workflow is framed as a practical way to improve ligand-based virtual screening for drug discovery, with cardiotoxicity prediction as the example task. The goal is to identify compounds that may block the human hERG potassium channel, a key antitarget associated with cardiotoxicity, so promising hits from earlier screening can be filtered before expensive experiments. The chapter emphasizes that a useful model is not just one that performs well numerically, but one that matches project constraints, handles uncertainty sensibly, and supports downstream decision-making in a real discovery pipeline.

The data workflow begins with acquiring a labeled hERG blockers dataset, then exploring, validating, and standardizing the molecular records so the model sees a consistent representation. The text stresses that real chemistry data are often messy, with missing values, conflicting labels, salts, stereochemistry issues, and assay variability, so curation and exploratory analysis are essential. After converting cleaned SMILES strings into standardized molecular objects, the molecules are encoded with Morgan fingerprints, producing sparse numerical features that summarize structural patterns and can be used to learn relationships between structure and hERG blocking activity.

Modeling starts with a linear supervised classifier trained on the fingerprint features, but the chapter shows that high training accuracy alone is misleading because the model generalizes less well under cross-validation and on the test set. It then introduces better evaluation practices such as cross-validation, precision, recall, F1, confusion matrices, and Matthews correlation coefficient, while also discussing class imbalance and applicability domain. To improve performance, the chapter applies regularization, explores nonlinear feature transformations, and uses pipelines with grid search and randomized search to tune hyperparameters without data leakage; the best model is saved, reloaded, and applied to new compounds, demonstrating a full end-to-end predictive workflow.

Key stages in our ML workflow.
(Left) Distribution of pIC50 values for the real hERG blockers dataset. (Right) Distribution of pIC50 values for hERG blockers dataset with simulated curation error.
Top row displays the structures of the compounds with highest experimentally measured pIC50. Bottom row displays the structures of the compounds with lowest experimentally measured pIC50.
Our model does not see molecules in the same way we do. SMILES are one method of storage information about chemical structures. Standardization streamlines the different views our model could have of a molecule into one well-defined representation and aligns that well-defined representation across all molecules in the dataset. Prior to standardization, each molecule could have been curated dataset following different conventions that confuse and alter how our model views them, negatively influence its learning.
After standardization, GBR-12909 has been neutralized and clofilium phosphate has had excess fragments removed. Our next step will be to represent the dataset as fingerprints, which doesn’t make sense for entries that would be more than one fragment.
Molecules to fingerprint bits share a many-to-many relationship. (Left) Heatmap showing sparsity of set fingerprint bits across the entire training data set. (Right) The distribution of how many bits are set per molecule in the dataset.
We can formally define our problem as a mathematical function, f∶ X→Y, that maps the set of all possible inputs, X (the full chemical space of druglike compounds), to the set of all possible outputs, Y (“yes” or “no” to hERG blocking).
The target function represents ground truth. It is an unknown function that maps input data to their corresponding target or label values. The difficulty is that we must learn the entire function from a few training instances. We will estimate model weights that fit the training points closely, while assuming that the learned function still generalizes to regions where we don’t have training instances. We also assume that the distribution of sampled data that constitutes our training set is equivalent to the target function’s distribution. The more data available to us, the more likely that both assumptions will hold.
Parametric ML model during training. Our ML model learns a function that maps each input data instance to a prediction about a property of interest. The loss and optimization functions measure and aggregate the performance of the model’s predictions. In tandem with a learning routine, the model’s weights are updated such that, in the next iteration of training, the model will reduce its previous error and perform better.
During inference, the ML model is exposed to new, previously unseen data and outputs predictions that are used by downstream components. There is no learning as weights are frozen and not adjusted further.
We can view our ML model as a function that learns correspondence between the structures in the input data and the output property we are modeling. To mediate this, we convert the molecule into fingerprint features that quantify its structure.
(Left) Initially, our untrained model misclassifies multiple instances. The model’s decision boundary will adjust with each training iteration. (Right) Our ML model can learn a decision boundary that partitions the input data into “hERG blocker” and “not hERG blocker” classes. Assuming our data is linearly separable with respect to hERG blocker classes, we hope to develop a linear model whose decision boundary correctly separates the training data and generalizes to new data that wasn’t in the training set.
k-fold cross validation to evaluate model candidates on training data split into train and validation folds. The best model is retrained on all training data and evaluated on the held-out test data. Not shown, but before deploying the best model to a production environment, we would also retrain it on all available data, including the test set.
Each cell represents the count of observations for a specific combination of true and predicted class values. Confusion matrices are not limited to binary classification problems; they can be extended to multi-class problems by including additional rows and columns to represent the various classes.
Discrepancy between our model’s performance on the training set and validation set is large for all four of our binary classification metrics. We need to consider methods that will reduce generalization errors.
Our model weights are exceedingly high given the model’s output space.
The original data set is not linearly separable. To fit the data set with a linear model, we can transform the data set into a new feature space that is linearly separable. The nonlinear decision boundary in the original space corresponds to a linear decision boundary in the transformed space.
Regularization has constrained our model’s weights, improving its generalizability.
The three structures with the most positive weights and the three structures with the most negative weights. Note that each bit can map to multiple structures. We just show the first structure for each bit. Blue, yellow, and grey represent the central atom, aromatic atoms, and aliphatic ring atoms, respectively. Asterisks represent wildcards.

Summary

  • We traversed a typical ML workflow: from problem definition to data acquisition and featurization, and to model training and evaluation. We ended with how to save and use our model on other data, though production deployment and maintenance is out of scope. In real life, we also need to continually reassess whether the model achieves its desired business objective and, if not, reinitiate project scoping or consider alternatives.
  • Early data exploration can help to identify curation issues, such as unit misannotations, or molecule standardization issues that threaten reproducibility and verity of our model.
  • We can use Scikit-Learn to train a linear classification model and evaluate it against a variety of metrics derived from confusion matrices. Cross-validation is a common strategy that efficiently uses all available training data for training and evaluation.
  • Overfitting negatively impacts our ML model’s ability to generalize to unseen data. Regularization mitigates overfitting by enforcing a tradeoff between making in-sample errors on the training set and constricting the magnitude of the model’s coefficient weights.
  • If our data breaks linearity assumptions, we can transform it into a nonlinear feature space and fit a linear model on the transformed data. The linearity in the model weights is the key property constituting a linear model. As long as the model weights remain linear, then we stay within the analytic realm of linear models.
  • We can construct a Scikit-Learn pipeline when searching for optimal hyperparameters. Grid search is most useful when the hyperparameter space is small and computationally feasible to exhaustively evaluate, or when we want to explicitly explore specific hyperparameter combinations. Randomized search is a more appealing alternative, especially in terms of efficiency, flexibility, exploration, and robustness.

FAQ

What is the goal of the ligand-based screening model in this chapter?

The goal is to predict whether a compound is a hERG blocker or non-blocker so that cardiotoxic risk can be filtered out early in the virtual screening pipeline.

Why is hERG blockage important in drug discovery?

hERG channel blockage is a well-known cause of cardiotoxicity, so compounds that block it should be identified and removed early to reduce late-stage failures and safety risks.

Why is this problem framed as binary supervised classification?

It is binary because each compound has one of two labels: hERG blocker or hERG non-blocker. It is supervised because the model learns from labeled examples with known experimental outcomes.

Why shouldn’t pIC50 be used directly as a training feature?

pIC50 was used to define the class label, so using it as a feature would leak target information. It is also experimentally derived and may contain missing values or measurement inconsistencies.

Why is data curation and standardization necessary before modeling?

Real molecular datasets can contain duplicates, inconsistent SMILES, salts, mixtures, stereochemistry issues, and conflicting assay data. Standardization creates a consistent molecular representation for fair comparison and better model learning.

What steps are included in the SMILES standardization pipeline?

The pipeline typically converts SMILES to molecules, cleans them up, keeps the largest fragment, neutralizes charges when possible, and canonicalizes the tautomer to produce a consistent representation.

Why are Morgan fingerprints used as features?

Morgan fingerprints provide a fixed-length numerical encoding of molecular substructures, making them suitable as machine learning inputs for learning structure-activity relationships.

Why can a model have high training accuracy but lower cross-validation performance?

This often indicates overfitting or leakage-like effects from near-duplicate compounds in the split. Cross-validation gives a better estimate of generalization to unseen data.

How do regularization and non-linear feature transforms improve the model?

Regularization reduces overly large coefficients and helps prevent overfitting. Non-linear transforms can help capture interactions between features when a simple linear boundary is not sufficient.

Why use a pipeline with grid search or randomized search?

A pipeline bundles preprocessing, featurization, and modeling into one reproducible workflow and helps prevent data leakage. Grid search and randomized search then tune hyperparameters efficiently to find the best-performing configuration.

pro $24.99 per month

  • access to all Manning books, MEAPs, liveVideos, liveProjects, and audiobooks!
  • choose one free eBook per month to keep
  • exclusive 50% discount on all purchases
  • renews monthly, pause or cancel renewal anytime

lite $19.99 per month

  • access to all Manning books, including MEAPs!

team

5, 10 or 20 seats+ for your team - learn more


choose your plan

team

monthly
annual
$49.99
$499.99
only $41.67 per month
  • five seats for your team
  • access to all Manning books, MEAPs, liveVideos, liveProjects, and audiobooks!
  • choose another free product every time you renew
  • choose twelve free products per year
  • exclusive 50% discount on all purchases
  • renews monthly, pause or cancel renewal anytime
  • renews annually, pause or cancel renewal anytime
  • Build AI Drug Discovery Pipelines ebook for free
choose your plan

team

monthly
annual
$49.99
$499.99
only $41.67 per month
  • five seats for your team
  • access to all Manning books, MEAPs, liveVideos, liveProjects, and audiobooks!
  • choose another free product every time you renew
  • choose twelve free products per year
  • exclusive 50% discount on all purchases
  • renews monthly, pause or cancel renewal anytime
  • renews annually, pause or cancel renewal anytime
  • Build AI Drug Discovery Pipelines ebook for free