liveBook · Manning

Grid search

As explained in Build AI Drug Discovery Pipelines

Grid search is a hyperparameter optimization method that evaluates models across a specified Cartesian product of candidate parameter values.

Grid search is a hyperparameter optimization method that evaluates every specified combination of candidate values. It is useful when the search space is small enough to examine exhaustively, such as choosing regularization, fingerprint, and model settings for cardiotoxicity prediction. section 3.4.3 section 3.5

A practical grid-search workflow:

  • Put preprocessing, molecule standardization, fingerprint generation, and the estimator into one Scikit-Learn pipeline. section 3.4.3
  • Specify candidate values using parameter names qualified by their pipeline step, such as penalty, alpha, fingerprint radius, and fingerprint size. section 3.4.3
  • Run GridSearchCV with a scoring metric and cross-validation, then inspect the best parameters and cross-validated score. section 3.4.3 section 3.4.3
  • Keep preprocessing inside the pipeline so each cross-validation fold refits transformations without leaking information between training and validation data. section 3.4.3

Cardiotoxicity classifier

A pipeline standardizes SMILES, generates fingerprints, and trains an SGDClassifier. A five-fold GridSearchCV evaluates penalties l1 and l2, alpha values 0.001–0.1, fingerprint radii 2 and 4, and sizes 1024 and 2048 using F1 scoring. One reported best configuration uses 2048 bits, radius 2, alpha 0.1, and l2 regularization, with a cross-validated score of 0.8809258265665167. section 3.4.3 section 3.4.3

Listing 3.14 Pipeline with GridSearchCV
from sklearn.model_selection import GridSearchCV, RandomizedSearchCV
from sklearn.pipeline import make_pipeline, Pipeline
from sklearn.preprocessing import PolynomialFeatures
 
cache_dir = "gs_linear_sgd"
pipe_linear_sgd = make_pipeline(
  SmilesToMols(),  # Transformer: Load & standardize SMILES
  FingerprintFeaturizer(),  # Transformer: Feature generation step
  SGDClassifier(),  # Estimator: linear model via SGD
  memory=cache_dir
)
 
param_grid_linear_sgd = [{
  'sgdclassifier__penalty': ["l2", "l1"],
  'sgdclassifier__alpha': [1e-3, 1e-2, 1e-1],
  'fingerprintfeaturizer__radius': [2, 4],
  'fingerprintfeaturizer__nBits': [1024, 2048],
}]
 
gs_linear_sgd = GridSearchCV(
  estimator=pipe_linear_sgd,
  param_grid=param_grid_linear_sgd,
  scoring="f1",
  cv=5,
  verbose=1,
)
 
gs_linear_sgd.fit(train_set.SMILES, train_set.Class)

Inspect the complete Pipeline and GridSearchCV implementation, including caching, parameter naming, five-fold validation, and fitting on training SMILES and labels. section 3.4.3

How Build AI Drug Discovery Pipelines covers it

How deep it goes
Explains exhaustive combinations, pipeline integration, cross-validation, leakage prevention, and inspected results; defers large-space efficiency to randomized search.
Examples
Demonstrates SGDClassifier selection using penalties, alpha values, fingerprint radii, fingerprint sizes, F1 scoring, and five-fold validation.
What it assumes
Assumes basic machine-learning workflow vocabulary while defining pipelines, transformers, estimators, training instances, and labels.
What you can do after
Evaluate candidate pipeline configurations and identify the best parameters using cross-validated performance.
How it connects
Connects hyperparameter tuning with pipelines, cross-validation, regularization, molecular fingerprints, and randomized search.

Also explained in

Compare how 7 books explain grid search →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Build AI Drug Discovery Pipelines. The section links point to the parts of the book it draws on.