Manifold learning reduces high-dimensional data by modeling it as lying on or near a lower-dimensional surface. Unlike PCA’s linear assumption, nonlinear methods can preserve structure that is locally simple but globally curved, such as a rolled Swiss roll. section 7.1.4
A practical manifold-learning workflow can:
- Represent compounds with fingerprints, then project them into two dimensions with UMAP. section 7.1.4
- Tune neighborhood size and minimum distance with cross-validation before using the embedding with a k-nearest-neighbors classifier. section 7.1.4
- Inspect projections for relationships involving compound activity and chemical series. 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 Python demonstrates UMAP with a Jaccard metric, a two-dimensional embedding, a k-nearest-neighbors classifier, and GridSearchCV. section 7.1.4

