Skip to content

Commit

Permalink
Quick change
Browse files Browse the repository at this point in the history
  • Loading branch information
kmkolasinski committed Oct 29, 2024
1 parent 1f904f6 commit 244e590
Showing 1 changed file with 130 additions and 0 deletions.
130 changes: 130 additions & 0 deletions notebooks/demo.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,130 @@
{
"cells": [
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"%load_ext autoreload\n",
"%autoreload 2"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"import umap\n",
"from sklearn.datasets import fetch_openml\n",
"import matplotlib.pyplot as plt\n",
"import seaborn as sns\n",
"\n",
"sns.set(context=\"paper\", style=\"white\")\n",
"\n",
"mnist = fetch_openml(\"mnist_784\", version=1)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"reducer = umap.UMAP(verbose=True, n_jobs=1)\n",
"embedding = reducer.fit_transform(mnist.data)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"fig, ax = plt.subplots(figsize=(12, 10))\n",
"color = mnist.target.astype(int)\n",
"plt.scatter(embedding[:, 0], embedding[:, 1], c=color, cmap=\"Spectral\", s=0.1)\n",
"plt.setp(ax, xticks=[], yticks=[])\n",
"plt.title(\"MNIST data embedded into two dimensions by UMAP\", fontsize=18)\n",
"plt.show()"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"import nano_umap\n",
"\n",
"nano_reducer = nano_umap.NanoUMAP(verbose=True, n_jobs=-1, n_epochs=500)\n",
"nano_embedding = nano_reducer.fit_transform(mnist.data)\n",
"\n",
"fig, ax = plt.subplots(figsize=(10, 10))\n",
"color = mnist.target.astype(int)\n",
"plt.scatter(nano_embedding[:, 0], nano_embedding[:, 1], c=color, cmap=\"Spectral\", s=0.1)\n",
"plt.setp(ax, xticks=[], yticks=[])\n",
"plt.show()"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"precomputed_umap_knn = nano_reducer._get_knn(mnist.data)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"nano_reducer = nano_umap.NanoUMAP(\n",
" precomputed_knn=precomputed_umap_knn,\n",
" learning_rate=2.0,\n",
" n_jobs=-1,\n",
" init=\"spectral\",\n",
" verbose=True,\n",
")\n",
"nano_embedding = nano_reducer.fit_transform(mnist.data)\n",
"fig, ax = plt.subplots(figsize=(7, 7))\n",
"color = mnist.target.astype(int)\n",
"plt.scatter(nano_embedding[:, 0], nano_embedding[:, 1], c=color, cmap=\"Spectral\", s=0.1)\n",
"plt.setp(ax, xticks=[], yticks=[])\n",
"plt.show()"
]
},
{
"cell_type": "code",
"execution_count": 131,
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "ml3.11",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.11.4"
}
},
"nbformat": 4,
"nbformat_minor": 2
}

0 comments on commit 244e590

Please sign in to comment.