liveBook · Manning

Linear classifier

As explained in Build AI Drug Discovery Pipelines

Linear classification assigns discrete classes using a threshold on a linear combination of input features.

A linear classifier assigns a binary class by combining feature values with learned weights and thresholding the resulting signal. In ligand-based screening, molecular fingerprints provide the features, while the target can be whether a compound blocks the hERG channel. The learned decision boundary separates “hERG blocker” from “not hERG blocker” when the classes are sufficiently separable. section 3.3.2 section 5.1.1

A practical workflow uses:

  • A predefined train/test split, with fingerprints computed for the training molecules and class labels retained separately. section 3.3.2
  • Scikit-Learn’s SGDClassifier, fitted to adjust the decision boundary through iterative optimization. section 3.3.2
  • Accuracy or other evaluation measures applied to predictions, rather than treating a high training score as proof of generalization. section 3.3.2 section 3.4.2

hERG blocker prediction

A classifier trained on molecular fingerprints achieved 0.964 accuracy on its training set. That result supports checking the held-out test set before concluding that blocker prediction generalizes. If the original fingerprint space is not linearly separable, polynomial feature transformations can create a space where a linear model produces a nonlinear boundary in the original features. section 3.3.2 section 3.4.2

Listing 3.7 Training a Linear Classifier
from sklearn.linear_model import SGDClassifier
RANDOM_SEED = 42
 
def split_data(df, split_col="Random Split"):
  train = df[df[split_col].str.contains("Train", na=False)]
  test = df[df[split_col].str.contains("Test", na=False)]
  return (
    train.sample(frac=1, random_state=RANDOM_SEED).reset_index(drop=True),
    test.sample(frac=1, random_state=RANDOM_SEED).reset_index(drop=True),
  )
 
train_set, test_set = split_data(herg_blockers)
train_fingerprints = np.stack(
    [compute_fingerprint(mol, 2, 2048) for mol in train_set.mol]
)
train_labels = train_set.Class
 
def train_sgd_classifier(X_train, y_train, **kwargs):
    params = {
        'random_state': RANDOM_SEED,
        'max_iter': 1000,
        'tol': 1e-3
    }
    params.update(kwargs)    #A
    clf = SGDClassifier(**params)    #B
    clf.fit(X_train, y_train)    #B
    return clf
 
lin_cls = train_sgd_classifier(train_fingerprints, train_labels)

Use the runnable listing to split the hERG data, compute fingerprints, configure SGDClassifier, and fit the classifier. section 3.3.2

How Build AI Drug Discovery Pipelines covers it

How deep it goes
Defines weighted signals, thresholds, decision boundaries, training, and evaluation, while deferring SGD internals to later treatment.
Examples
Demonstrates hERG blocker prediction, a 0.964 training accuracy, and polynomially transformed features for nonlinearly separable data.
What it assumes
Assumes molecule structures can be represented as fingerprints and targets can be encoded as binary class labels.
What you can do after
Apply it via Scikit-Learn to train classifiers, generate predictions, and evaluate performance on held-out data.
How it connects
Connects molecular fingerprints, stochastic gradient descent, logistic regression, binary classification, and polynomial feature transformations.

Also explained in

Compare how 2 books explain linear classifier →

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.