liveBook · Manning

Enrichment factor

As explained in Build AI Drug Discovery Pipelines

Enrichment factor is a screening metric that compares the proportion of active compounds found in an early-ranked subset with the proportion expected by random selection.

Enrichment factor (EF) measures early recognition in virtual screening: it compares the active-compound proportion in a top-ranked subset with the proportion expected from random selection. Higher enrichment means more likely actives are found sooner, reducing the compounds that require experimental testing. section 2.0 section 8.1.3

A practical EF workflow is:

  • Check that the model’s training compounds cover the screened library’s chemical space and remove any compounds already used for training. section 8.1.3
  • Score every library compound, rank the predictions, and retain a specified early fraction such as the top 0.5%, 1%, 2%, or 5%. section 8.1.3
  • Compare actives found in each subset with the random-selection expectation; interpret EF alongside random and optimal baselines. section 8.1.3

A 1% screening example

If random selection would find one active compound in the top 1% but a ranked method finds five, EF(1%) equals 5. An EF of 1 represents random-level enrichment. section 8.1.3

EF(X%)=(Number of actives found in top X% of the ranked list)Total actives in dataset×(X%100)

Use the equation to calculate EF at any chosen screening percentage from active counts, total actives, and the ranked-list fraction. section 8.1.3

Listing 8.4 Calculating Enrichment Factors
import math
 
def calculate_enrichment_factors(
    y_true, y_pred, activity_threshold=6.3,
    ef_percentages=[0.005, 0.01, 0.02, 0.05]
):
    y_true_binary = (y_true >= activity_threshold).astype(int)
    sorted_indices = np.argsort(y_pred)[::-1]
    n_actives = int(np.sum(y_true_binary))    #A
    n_total = len(y_true_binary)    #B
    if n_actives == 0 or n_total == 0:    #C
        raise ValueError(
            "Need at least one active and a non-empty dataset."
        )
    enrichment_factors = {}
    for percentage in ef_percentages:    #D
        n_compounds = max(1, math.ceil(    #E
            n_total * percentage))  #E
        top = sorted_indices[:n_compounds]
        n_actives_found = int(np.sum(y_true_binary[top]))
        ef_model = (    #F
            (n_actives_found / n_compounds)    #F
            / (n_actives / n_total)    #F
        )  #F
        ef_optimal = min(1 / percentage, n_total / n_actives)  #G
        ef_random = 1.0  #H
        enrichment_factors[f"EF{percentage*100:.1f}%"] = {
            "Model": ef_model,
            "Optimal": ef_optimal,
            "Random": ef_random
        }
    return enrichment_factors

Use the Python implementation to threshold activities, sort predictions, calculate EF across several percentages, and reject empty or all-inactive datasets. section 8.1.3

How Build AI Drug Discovery Pipelines covers it

How deep it goes
Defines the comparison, gives an equation and worked example, and implements multiple cutoff calculations while emphasizing baseline interpretation.
Examples
Uses a 1% example with five retrieved actives, Python calculations, and model, optimal, and random enrichment comparisons.
What it assumes
Assumes ranked compound predictions and activity labels, while defining early recognition, active compounds, and random expectations.
What you can do after
Evaluate ranked screening results by calculating enrichment at selected library percentages and comparing against random selection.
How it connects
Connects virtual screening with scoring functions, active compounds, chemical-space applicability, and random or optimal selection.

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.