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






