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
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_factorsUse the Python implementation to threshold activities, sort predictions, calculate EF across several percentages, and reject empty or all-inactive datasets. section 8.1.3
