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
