Sharedumap.ipynbOpen in CoCalc
Author: Harald Schilly
Views : 4

UMAP

Testing iris dataset: https://umap-learn.readthedocs.io/en/latest/basic_usage.html#iris-data

Kernel: Python 3 (Ubuntu Linux)

import numpy as np from sklearn.datasets import load_iris, load_digits from sklearn.model_selection import train_test_split import matplotlib.pyplot as plt import seaborn as sns import pandas as pd sns.set(style='white', context='notebook', rc={'figure.figsize':(14,10)})
iris = load_iris() iris_df = pd.DataFrame(iris.data, columns=iris.feature_names) iris_df['species'] = pd.Series(iris.target).map(dict(zip(range(3),iris.target_names))) sns.pairplot(iris_df, hue='species')
import umap reducer = umap.UMAP()
embedding = reducer.fit_transform(iris.data) embedding.shape
/usr/local/lib/python3.6/dist-packages/umap/spectral.py:229: UserWarning: Embedding a total of 2 separate connected components using meta-embedding (experimental) n_components
(150, 2)
plt.scatter( embedding[:, 0], embedding[:, 1], c=[sns.color_palette()[x] for x in iris.target]) plt.gca().set_aspect('equal', 'datalim') plt.title('UMAP projection of the Iris dataset', fontsize=24)
Text(0.5,1,'UMAP projection of the Iris dataset')