liveBook · Manning

Precision

As explained in Build AI Drug Discovery Pipelines

Precision is the proportion of predicted positive instances that are truly positive.

Precision measures the proportion of predicted positive instances that are truly positive. It answers: when a model flags a compound as active, how often is that prediction correct? section 3.3.3

For a binary classifier, precision equals TP divided by TP plus FP. It therefore focuses on the quality of positive predictions and penalizes false positives. section 3.3.3

Precision should be read with recall, which accounts for missed positives. A model can achieve high precision by making few positive predictions while still overlooking many real positives. section 3.3.3

Drug-screening interpretation

In a CYP3A4 inhibition classifier, precision is 0.76 and recall is 0.74 on the validation set. The precision value summarizes the reliability of predicted inhibitors, while recall summarizes recovered inhibitors. section 5.1.2

Confusion-matrix calculation

A confusion matrix containing 259 true positives and 13 false positives gives precision of 259 divided by 259 plus 13, or approximately 0.95. The same model has one false negative, so recall provides additional context.

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.74

Inspect a runnable scikit-learn workflow that trains logistic regression on CYP3A4 inhibition data and computes precision alongside accuracy and recall. section 5.1.2

How Build AI Drug Discovery Pipelines covers it

How deep it goes
Defines the metric from confusion-matrix counts, gives its equation, and contrasts it with recall without developing threshold selection.
Examples
Uses CYP3A4 inhibition, Morgan fingerprints, logistic regression, and a confusion matrix from ligand-screening predictions.
What it assumes
Assumes binary classification and predicted labels, while defining true positives, false positives, false negatives, and true negatives.
What you can do after
Evaluate binary classifiers with precision and interpret positive-prediction quality alongside recall.
How it connects
Connects precision to confusion matrices, recall, F1 score, class imbalance, cross-validation, and generalization error.

Also explained in

Compare how 27 books explain precision →

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.