{ "cells": [ { "cell_type": "code", "execution_count": 1, "id": "6826454b", "metadata": { "execution": { "iopub.execute_input": "2026-05-11T22:13:41.957199Z", "iopub.status.busy": "2026-05-11T22:13:41.957123Z", "iopub.status.idle": "2026-05-11T22:13:41.974095Z", "shell.execute_reply": "2026-05-11T22:13:41.973776Z" }, "tags": [ "remove-input", "remove-output" ] }, "outputs": [], "source": [ "# This cell does not render in the docs because of the tag `remove-input`\n", "%load_ext autoreload\n", "%autoreload 2\n", "\n", "import warnings\n", "\n", "warnings.filterwarnings(\"ignore\")" ] }, { "cell_type": "markdown", "id": "bee6f910", "metadata": {}, "source": [ "# Basic Usage\n", "\n", "## A drop in replacement for UMAP\n", "\n", "In simple cases, Glass Box UMAP can serve as a drop-in replacement for UMAP.\n", "\n", "```diff\n", "- from umap import UMAP\n", "+ from glass_box_umap import GlassBoxUMAP\n", "\n", "- UMAP().fit_transform(X)\n", "+ GlassBoxUMAP().fit_transform(X)\n", "```\n", "\n", "Let's illustrate this with an example. The [UCI Wine](https://archive.ics.uci.edu/dataset/109/wine) dataset contains chemical measurements of wines from a region in Italy, produced using one of three cultivars (grape varieties). The dataset includes 178 wines (observations), each with measurements across 13 different chemical features and a label indicating which cultivar the wine was produced from.\n", "\n", "The dataset can be loaded from [sklearn.datasets](https://scikit-learn.org/stable/api/sklearn.datasets.html)." ] }, { "cell_type": "code", "execution_count": 2, "id": "943e421b", "metadata": { "execution": { "iopub.execute_input": "2026-05-11T22:13:41.975523Z", "iopub.status.busy": "2026-05-11T22:13:41.975452Z", "iopub.status.idle": "2026-05-11T22:13:42.245984Z", "shell.execute_reply": "2026-05-11T22:13:42.245517Z" } }, "outputs": [ { "data": { "text/html": [ "
| \n", " | alcohol | \n", "malic_acid | \n", "ash | \n", "alcalinity_of_ash | \n", "magnesium | \n", "total_phenols | \n", "flavanoids | \n", "nonflavanoid_phenols | \n", "proanthocyanins | \n", "color_intensity | \n", "hue | \n", "od280/od315_of_diluted_wines | \n", "proline | \n", "
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 0 | \n", "14.23 | \n", "1.71 | \n", "2.43 | \n", "15.6 | \n", "127.0 | \n", "2.80 | \n", "3.06 | \n", "0.28 | \n", "2.29 | \n", "5.64 | \n", "1.04 | \n", "3.92 | \n", "1065.0 | \n", "
| 1 | \n", "13.20 | \n", "1.78 | \n", "2.14 | \n", "11.2 | \n", "100.0 | \n", "2.65 | \n", "2.76 | \n", "0.26 | \n", "1.28 | \n", "4.38 | \n", "1.05 | \n", "3.40 | \n", "1050.0 | \n", "
| 2 | \n", "13.16 | \n", "2.36 | \n", "2.67 | \n", "18.6 | \n", "101.0 | \n", "2.80 | \n", "3.24 | \n", "0.30 | \n", "2.81 | \n", "5.68 | \n", "1.03 | \n", "3.17 | \n", "1185.0 | \n", "
| 3 | \n", "14.37 | \n", "1.95 | \n", "2.50 | \n", "16.8 | \n", "113.0 | \n", "3.85 | \n", "3.49 | \n", "0.24 | \n", "2.18 | \n", "7.80 | \n", "0.86 | \n", "3.45 | \n", "1480.0 | \n", "
| 4 | \n", "13.24 | \n", "2.59 | \n", "2.87 | \n", "21.0 | \n", "118.0 | \n", "2.80 | \n", "2.69 | \n", "0.39 | \n", "1.82 | \n", "4.32 | \n", "1.04 | \n", "2.93 | \n", "735.0 | \n", "
| ... | \n", "... | \n", "... | \n", "... | \n", "... | \n", "... | \n", "... | \n", "... | \n", "... | \n", "... | \n", "... | \n", "... | \n", "... | \n", "... | \n", "
| 173 | \n", "13.71 | \n", "5.65 | \n", "2.45 | \n", "20.5 | \n", "95.0 | \n", "1.68 | \n", "0.61 | \n", "0.52 | \n", "1.06 | \n", "7.70 | \n", "0.64 | \n", "1.74 | \n", "740.0 | \n", "
| 174 | \n", "13.40 | \n", "3.91 | \n", "2.48 | \n", "23.0 | \n", "102.0 | \n", "1.80 | \n", "0.75 | \n", "0.43 | \n", "1.41 | \n", "7.30 | \n", "0.70 | \n", "1.56 | \n", "750.0 | \n", "
| 175 | \n", "13.27 | \n", "4.28 | \n", "2.26 | \n", "20.0 | \n", "120.0 | \n", "1.59 | \n", "0.69 | \n", "0.43 | \n", "1.35 | \n", "10.20 | \n", "0.59 | \n", "1.56 | \n", "835.0 | \n", "
| 176 | \n", "13.17 | \n", "2.59 | \n", "2.37 | \n", "20.0 | \n", "120.0 | \n", "1.65 | \n", "0.68 | \n", "0.53 | \n", "1.46 | \n", "9.30 | \n", "0.60 | \n", "1.62 | \n", "840.0 | \n", "
| 177 | \n", "14.13 | \n", "4.10 | \n", "2.74 | \n", "24.5 | \n", "96.0 | \n", "2.05 | \n", "0.76 | \n", "0.56 | \n", "1.35 | \n", "9.20 | \n", "0.61 | \n", "1.60 | \n", "560.0 | \n", "
178 rows × 13 columns
\n", "\\n\"+\n", " \"BokehJS does not appear to have successfully loaded. If loading BokehJS from CDN, this \\n\"+\n", " \"may be due to a slow or bad network connection. Possible fixes:\\n\"+\n", " \"
\\n\"+\n", " \"\\n\"+\n",
" \"from bokeh.resources import INLINE\\n\"+\n",
" \"output_notebook(resources=INLINE)\\n\"+\n",
" \"\\n\"+\n",
" \"\\n\"+\n \"BokehJS does not appear to have successfully loaded. If loading BokehJS from CDN, this \\n\"+\n \"may be due to a slow or bad network connection. Possible fixes:\\n\"+\n \"
\\n\"+\n \"\\n\"+\n \"from bokeh.resources import INLINE\\n\"+\n \"output_notebook(resources=INLINE)\\n\"+\n \"\\n\"+\n \"