Logistic regression is a binary classification method that converts a weighted feature signal into a value between 0 and 1 with the sigmoid function. Interpreting that value as a class probability lets a practitioner choose a decision threshold, commonly 0.5, to classify compounds as inhibitors or noninhibitors. section 5.1.1
For a molecule, the input features can be numerical fingerprints derived from its chemical structure. Training adjusts the model weights with gradient descent to reduce binary cross-entropy, which penalizes probabilities that diverge from the true binary class. section 5.1.1 section 1.2.3
A practical drug-discovery workflow uses logistic regression to:
- Represent compounds with RDKit molecular fingerprints. section 1.2.3 section 5.1.2
- Predict whether a compound inhibits the CYP3A4 drug-metabolizing enzyme. section 5.1.2 section 5.5
- Compare predictions with accuracy, precision, and recall rather than accuracy alone. section 5.1.2
- Inspect probability quality and threshold behavior with PR or ROC curves and calibration diagnostics. section 5.5
CYP3A4 inhibition
A logistic regressor trained on CYP3A4 inhibition data achieved 0.78 validation accuracy, with 0.76 precision and 0.74 recall. Because an always-negative dummy model reached 0.55 accuracy, the baseline and class balance matter when interpreting performance. section 5.1.2
Listing 5.1 Train and Evaluate Logistic Regressor on the CYP3A4 Inhibition Data Set
from sklearn.metrics import accuracy_score, precision_score, recall_score
from sklearn.linear_model import LogisticRegression
from tdc.single_pred import ADME
from utils import compute_fingerprint
import numpy as np
import pandas as pd
from rdkit.Chem import PandasTools
def process_df(df):
df = df.rename(columns={'Y': 'Inhibitor'})
PandasTools.AddMoleculeColumnToFrame(df, 'Drug', 'Molecule')
df = df.dropna()
df['fingerprints'] = df['Molecule'].apply(
compute_fingerprint, r=2, nBits=2048 # r = Morgan radius; 2048-bit vector
)
fingerprints = np.stack(df.fingerprints.tolist())
return df, fingerprints
data = ADME(name='CYP3A4_Veith')
splits = data.get_split('scaffold')
train_df, valid_df, test_df = \
splits['train'], splits['valid'], splits['test']
train_df, train_fingerprints = process_df(train_df)
val_df, val_fingerprints = process_df(valid_df)
test_df, test_fingerprints = process_df(test_df)
lr_model = LogisticRegression()
lr_model.fit(train_fingerprints, train_df.Inhibitor)
val_preds = lr_model.predict(val_fingerprints) #A
val_proba_inhibitor = lr_model.predict_proba(val_fingerprints)[:, 1] #B
print(f"Accuracy: {accuracy_score(val_df.Inhibitor, val_preds):.2f}")
# Output -> Accuracy: 0.78
print(f"Precision: {precision_score(val_df.Inhibitor, val_preds):.2f}")
# Output -> Precision: 0.76
print(f"Recall: {recall_score(val_df.Inhibitor, val_preds):.2f}")
# Output -> Recall: 0.74Runnable Scikit-Learn code processes molecular structures, computes Morgan fingerprints, obtains a scaffold split, and evaluates predictions with classification metrics. section 5.1.2















