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

