liveBook · Manning

Jaccard distance

As explained in Build AI Drug Discovery Pipelines

Jaccard distance is a dissimilarity measure equal to one minus the ratio of set intersection size to set union size.

Jaccard distance measures dissimilarity between sets: it equals one minus the proportion of shared elements in their union. For molecular fingerprints, it serves as an analogue to Tanimoto similarity, helping UMAP place chemically similar compounds near one another. section 7.1.4

In a two-dimensional UMAP embedding, the metric influences high-dimensional relationships before compounds are moved closer or farther apart. The resulting layout preserves local or broader chemical structure according to n_neighbors, while min_dist controls cluster tightness. section 7.1.4

COVID Moonshot compound embedding

A UMAP-plus-k-nearest-neighbors pipeline uses metric="jaccard" and n_components=2 to embed fingerprints, then tunes n_neighbors and min_dist with grid search and three-fold cross-validation. section 7.1.4

Listing 7.4 Apply UMAP on COVID Moonshot Data Set
import umap
from sklearn.model_selection import GridSearchCV
from sklearn.pipeline import Pipeline
from sklearn.neighbors import KNeighborsClassifier
 
drh_data["retro_hit"] = \
    drh_data.pert_iname.isin(set(retrospective_hits_in_drh))
train_labels = (data["label"] == 1).values    #A
test_labels = drh_data["retro_hit"].values    #B
train_fps = fingerprints
test_fps = unseen_fingerprints
 
umap_params = {
    'umap__n_neighbors': [5, 10, 15],
    'umap__min_dist': [0.1, 0.2, 0.3],
}
 
pipeline = Pipeline([
    ('umap', umap.UMAP(metric="jaccard", n_components=2)),
    ('knn', KNeighborsClassifier(n_neighbors=5)),
])    #C
 
grid_search = GridSearchCV(
    pipeline, umap_params, cv=3, scoring='f1_micro', n_jobs=-1)
grid_search.fit(train_fps, train_labels)
print(f"Best parameters: {grid_search.best_params_}")
print(f"Best cross-validation score: {grid_search.best_score_}")
 
best_model = grid_search.best_estimator    #D
best_model.fit(train_fps, train_labels)

Runnable pipeline code shows Jaccard distance applied to fingerprints alongside UMAP, classification, and cross-validation. section 7.1.4

How Build AI Drug Discovery Pipelines covers it

How deep it goes
Explains its fingerprint role and embedding effects, then stops short of deriving the metric mathematically.
Examples
Demonstrates UMAP projections of COVID Moonshot compounds and compares activity and chemical-series layouts.
What it assumes
Assumes molecular fingerprints and similarity terminology, while introducing their use within UMAP chemical-space visualization.
What you can do after
Apply Jaccard distance through UMAP and scikit-learn pipelines to embed molecular fingerprints and tune neighborhood structure.
How it connects
Connects Jaccard distance with molecular fingerprints, Tanimoto similarity, UMAP, nearest neighbors, and chemical space.

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.