mirror of
https://github.com/NVIDIA/dgx-spark-playbooks.git
synced 2026-04-24 10:53:52 +00:00
2312 lines
236 KiB
Plaintext
2312 lines
236 KiB
Plaintext
|
|
{
|
||
|
|
"cells": [
|
||
|
|
{
|
||
|
|
"cell_type": "markdown",
|
||
|
|
"metadata": {
|
||
|
|
"id": "ZhTWAPo7X5-I"
|
||
|
|
},
|
||
|
|
"source": [
|
||
|
|
"# Getting Started with cuML's accelerator mode (cuml.accel)\n"
|
||
|
|
]
|
||
|
|
},
|
||
|
|
{
|
||
|
|
"cell_type": "markdown",
|
||
|
|
"metadata": {
|
||
|
|
"id": "BinKvOgMYOCp"
|
||
|
|
},
|
||
|
|
"source": [
|
||
|
|
"cuML is a Python GPU library for accelerating machine learning models using a scikit-learn-like API.\n",
|
||
|
|
"\n",
|
||
|
|
"cuML now has an accelerator mode (cuml.accel) which allows you to bring accelerated computing to existing workflows with zero code changes required. In addition to scikit-learn, cuml.accel also provides acceleration to algorithms found in umap-learn (UMAP) and hdbscan (HDBSCAN).\n",
|
||
|
|
"\n",
|
||
|
|
"This notebook is a brief introduction to cuml.accel.\n",
|
||
|
|
"\n",
|
||
|
|
"**Author:** Mitesh Patel, Allison Ding <br>\n",
|
||
|
|
"**Date:** October 3, 2025"
|
||
|
|
]
|
||
|
|
},
|
||
|
|
{
|
||
|
|
"cell_type": "markdown",
|
||
|
|
"metadata": {
|
||
|
|
"id": "ylUzZjM-mRMH"
|
||
|
|
},
|
||
|
|
"source": [
|
||
|
|
"# ⚠️ Verify your setup"
|
||
|
|
]
|
||
|
|
},
|
||
|
|
{
|
||
|
|
"cell_type": "markdown",
|
||
|
|
"metadata": {
|
||
|
|
"id": "e_AtDRMEZQd-"
|
||
|
|
},
|
||
|
|
"source": [
|
||
|
|
"First, we'll verfiy that we are running on an NVIDIA GPU:"
|
||
|
|
]
|
||
|
|
},
|
||
|
|
{
|
||
|
|
"cell_type": "code",
|
||
|
|
"execution_count": 1,
|
||
|
|
"metadata": {},
|
||
|
|
"outputs": [
|
||
|
|
{
|
||
|
|
"name": "stdout",
|
||
|
|
"output_type": "stream",
|
||
|
|
"text": [
|
||
|
|
"Sun Oct 5 21:26:06 2025 \n",
|
||
|
|
"+-----------------------------------------------------------------------------------------+\n",
|
||
|
|
"| NVIDIA-SMI 580.82.09 Driver Version: 580.82.09 CUDA Version: 13.0 |\n",
|
||
|
|
"+-----------------------------------------+------------------------+----------------------+\n",
|
||
|
|
"| GPU Name Persistence-M | Bus-Id Disp.A | Volatile Uncorr. ECC |\n",
|
||
|
|
"| Fan Temp Perf Pwr:Usage/Cap | Memory-Usage | GPU-Util Compute M. |\n",
|
||
|
|
"| | | MIG M. |\n",
|
||
|
|
"|=========================================+========================+======================|\n",
|
||
|
|
"| 0 NVIDIA GB10 Off | 0000000F:01:00.0 Off | N/A |\n",
|
||
|
|
"| N/A 38C P0 5W / N/A | Not Supported | 0% Default |\n",
|
||
|
|
"| | | N/A |\n",
|
||
|
|
"+-----------------------------------------+------------------------+----------------------+\n",
|
||
|
|
"\n",
|
||
|
|
"+-----------------------------------------------------------------------------------------+\n",
|
||
|
|
"| Processes: |\n",
|
||
|
|
"| GPU GI CI PID Type Process name GPU Memory |\n",
|
||
|
|
"| ID ID Usage |\n",
|
||
|
|
"|=========================================================================================|\n",
|
||
|
|
"| 0 N/A N/A 3405 G /usr/lib/xorg/Xorg 242MiB |\n",
|
||
|
|
"| 0 N/A N/A 3562 G /usr/bin/gnome-shell 50MiB |\n",
|
||
|
|
"+-----------------------------------------------------------------------------------------+\n"
|
||
|
|
]
|
||
|
|
}
|
||
|
|
],
|
||
|
|
"source": [
|
||
|
|
"!nvidia-smi"
|
||
|
|
]
|
||
|
|
},
|
||
|
|
{
|
||
|
|
"cell_type": "markdown",
|
||
|
|
"metadata": {
|
||
|
|
"id": "qC3fevZecnns"
|
||
|
|
},
|
||
|
|
"source": [
|
||
|
|
"With classical machine learning, there is a wide range of interesting problems we can explore. In this tutorial we'll examine 3 of the more popular use cases: classification, clustering, and dimensionality reduction."
|
||
|
|
]
|
||
|
|
},
|
||
|
|
{
|
||
|
|
"cell_type": "markdown",
|
||
|
|
"metadata": {},
|
||
|
|
"source": [
|
||
|
|
"# GPU-Accelerated Machine Learning"
|
||
|
|
]
|
||
|
|
},
|
||
|
|
{
|
||
|
|
"cell_type": "markdown",
|
||
|
|
"metadata": {},
|
||
|
|
"source": [
|
||
|
|
"The notebook magic command `%load_ext cuml.accel` enables automatic GPU acceleration for machine learning code written with libraries like UMAP and HDBSCAN, so models can train and run on NVIDIA GPUs without code changes or manual conversions. \n",
|
||
|
|
"\n",
|
||
|
|
"After activating this extension, supported estimators and algorithms are dispatched to the GPU for faster computation, and any operations not yet accelerated will seamlessly fall back to CPU execution. This approach is ideal for accelerating existing workflows in Jupyter or IPython environments, allowing significant speedups with minimal effort"
|
||
|
|
]
|
||
|
|
},
|
||
|
|
{
|
||
|
|
"cell_type": "code",
|
||
|
|
"execution_count": 2,
|
||
|
|
"metadata": {},
|
||
|
|
"outputs": [],
|
||
|
|
"source": [
|
||
|
|
"%load_ext cuml.accel"
|
||
|
|
]
|
||
|
|
},
|
||
|
|
{
|
||
|
|
"cell_type": "markdown",
|
||
|
|
"metadata": {},
|
||
|
|
"source": [
|
||
|
|
"# Classification"
|
||
|
|
]
|
||
|
|
},
|
||
|
|
{
|
||
|
|
"cell_type": "markdown",
|
||
|
|
"metadata": {},
|
||
|
|
"source": [
|
||
|
|
"Let's load a dataset and see how we can use scikit-learn to classify that data. For this example we'll use the Coverage Type dataset, which contains a number of features that can be used to predict forest cover type, such as elevation, aspect, slope, and soil-type.\n",
|
||
|
|
"\n",
|
||
|
|
"More information on this dataset can be found at https://archive.ics.uci.edu/dataset/31/covertype."
|
||
|
|
]
|
||
|
|
},
|
||
|
|
{
|
||
|
|
"cell_type": "code",
|
||
|
|
"execution_count": 4,
|
||
|
|
"metadata": {},
|
||
|
|
"outputs": [],
|
||
|
|
"source": [
|
||
|
|
"import pandas as pd\n",
|
||
|
|
"import numpy as np\n",
|
||
|
|
"from sklearn.svm import SVC, LinearSVC\n",
|
||
|
|
"from sklearn.model_selection import train_test_split\n",
|
||
|
|
"from sklearn.metrics import classification_report, accuracy_score"
|
||
|
|
]
|
||
|
|
},
|
||
|
|
{
|
||
|
|
"cell_type": "code",
|
||
|
|
"execution_count": 5,
|
||
|
|
"metadata": {},
|
||
|
|
"outputs": [],
|
||
|
|
"source": [
|
||
|
|
"url = \"https://archive.ics.uci.edu/ml/machine-learning-databases/covtype/covtype.data.gz\"\n",
|
||
|
|
"\n",
|
||
|
|
"# Column names for the dataset (from UCI Covertype description)\n",
|
||
|
|
"columns = ['Elevation', 'Aspect', 'Slope', 'Horizontal_Distance_To_Hydrology', 'Vertical_Distance_To_Hydrology',\n",
|
||
|
|
" 'Horizontal_Distance_To_Roadways', 'Hillshade_9am', 'Hillshade_Noon', 'Hillshade_3pm',\n",
|
||
|
|
" 'Horizontal_Distance_To_Fire_Points', 'Wilderness_Area1', 'Wilderness_Area2', 'Wilderness_Area3',\n",
|
||
|
|
" 'Wilderness_Area4', 'Soil_Type1', 'Soil_Type2', 'Soil_Type3', 'Soil_Type4', 'Soil_Type5', 'Soil_Type6',\n",
|
||
|
|
" 'Soil_Type7', 'Soil_Type8', 'Soil_Type9', 'Soil_Type10', 'Soil_Type11', 'Soil_Type12', 'Soil_Type13',\n",
|
||
|
|
" 'Soil_Type14', 'Soil_Type15', 'Soil_Type16', 'Soil_Type17', 'Soil_Type18', 'Soil_Type19', 'Soil_Type20',\n",
|
||
|
|
" 'Soil_Type21', 'Soil_Type22', 'Soil_Type23', 'Soil_Type24', 'Soil_Type25', 'Soil_Type26', 'Soil_Type27',\n",
|
||
|
|
" 'Soil_Type28', 'Soil_Type29', 'Soil_Type30', 'Soil_Type31', 'Soil_Type32', 'Soil_Type33', 'Soil_Type34',\n",
|
||
|
|
" 'Soil_Type35', 'Soil_Type36', 'Soil_Type37', 'Soil_Type38', 'Soil_Type39', 'Soil_Type40', 'Cover_Type']\n",
|
||
|
|
"\n",
|
||
|
|
"data = pd.read_csv(url, header=None)\n",
|
||
|
|
"data.columns=columns"
|
||
|
|
]
|
||
|
|
},
|
||
|
|
{
|
||
|
|
"cell_type": "code",
|
||
|
|
"execution_count": 6,
|
||
|
|
"metadata": {},
|
||
|
|
"outputs": [
|
||
|
|
{
|
||
|
|
"data": {
|
||
|
|
"text/plain": [
|
||
|
|
"(581012, 55)"
|
||
|
|
]
|
||
|
|
},
|
||
|
|
"execution_count": 6,
|
||
|
|
"metadata": {},
|
||
|
|
"output_type": "execute_result"
|
||
|
|
}
|
||
|
|
],
|
||
|
|
"source": [
|
||
|
|
"data.shape"
|
||
|
|
]
|
||
|
|
},
|
||
|
|
{
|
||
|
|
"cell_type": "markdown",
|
||
|
|
"metadata": {},
|
||
|
|
"source": [
|
||
|
|
"Next, we'll separate out the classification variable (Cover_Type) from the rest of the data. This is what we will aim to predict with our classification model. We can also split our dataset into training and test data using the scikit-learn train_test_split function."
|
||
|
|
]
|
||
|
|
},
|
||
|
|
{
|
||
|
|
"cell_type": "code",
|
||
|
|
"execution_count": 7,
|
||
|
|
"metadata": {},
|
||
|
|
"outputs": [],
|
||
|
|
"source": [
|
||
|
|
"X, y = data.drop('Cover_Type', axis=1), data['Cover_Type']\n",
|
||
|
|
"X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2)"
|
||
|
|
]
|
||
|
|
},
|
||
|
|
{
|
||
|
|
"cell_type": "markdown",
|
||
|
|
"metadata": {},
|
||
|
|
"source": [
|
||
|
|
"Now that we have our dataset split, we're ready to run a model. To start, we will just run the model using the sklearn library with a starting max depth of 5 and all of the features. Note that we can set n_jobs=-1 to utilize all available CPU cores for fitting the trees -- this will ensure we get the best performance possible on our system's CPU."
|
||
|
|
]
|
||
|
|
},
|
||
|
|
{
|
||
|
|
"cell_type": "code",
|
||
|
|
"execution_count": null,
|
||
|
|
"metadata": {},
|
||
|
|
"outputs": [],
|
||
|
|
"source": [
|
||
|
|
"%%time\n",
|
||
|
|
"clf = LinearSVC()\n",
|
||
|
|
"clf.fit(X_train, y_train)"
|
||
|
|
]
|
||
|
|
},
|
||
|
|
{
|
||
|
|
"cell_type": "markdown",
|
||
|
|
"metadata": {},
|
||
|
|
"source": [
|
||
|
|
"In about 2 minutes, we were able to fit our tree model using scikit-learn. This is not bad! Let's use the model we just trained to predict coverage types in our test dataset and take a look at the accuracy of our model."
|
||
|
|
]
|
||
|
|
},
|
||
|
|
{
|
||
|
|
"cell_type": "code",
|
||
|
|
"execution_count": null,
|
||
|
|
"metadata": {},
|
||
|
|
"outputs": [],
|
||
|
|
"source": [
|
||
|
|
"%%time\n",
|
||
|
|
"y_pred = clf.predict(X_test)\n",
|
||
|
|
"accuracy_score(y_test, y_pred)"
|
||
|
|
]
|
||
|
|
},
|
||
|
|
{
|
||
|
|
"cell_type": "markdown",
|
||
|
|
"metadata": {},
|
||
|
|
"source": [
|
||
|
|
"We can also print out a full classification report to better understand how we predicted different Coverage_Type categories."
|
||
|
|
]
|
||
|
|
},
|
||
|
|
{
|
||
|
|
"cell_type": "code",
|
||
|
|
"execution_count": null,
|
||
|
|
"metadata": {},
|
||
|
|
"outputs": [
|
||
|
|
{
|
||
|
|
"name": "stdout",
|
||
|
|
"output_type": "stream",
|
||
|
|
"text": [
|
||
|
|
" precision recall f1-score support\n",
|
||
|
|
"\n",
|
||
|
|
" 1 0.39 0.28 0.33 42371\n",
|
||
|
|
" 2 0.54 0.75 0.63 56772\n",
|
||
|
|
" 3 0.65 0.61 0.63 7146\n",
|
||
|
|
" 4 0.00 0.00 0.00 546\n",
|
||
|
|
" 5 0.00 0.00 0.00 1907\n",
|
||
|
|
" 6 0.00 0.00 0.00 3454\n",
|
||
|
|
" 7 0.00 0.00 0.00 4007\n",
|
||
|
|
"\n",
|
||
|
|
" accuracy 0.51 116203\n",
|
||
|
|
" macro avg 0.23 0.23 0.23 116203\n",
|
||
|
|
"weighted avg 0.45 0.51 0.46 116203\n",
|
||
|
|
"\n"
|
||
|
|
]
|
||
|
|
},
|
||
|
|
{
|
||
|
|
"name": "stderr",
|
||
|
|
"output_type": "stream",
|
||
|
|
"text": [
|
||
|
|
"/home/nvidia/miniconda3/envs/rapids-25.10/lib/python3.12/site-packages/sklearn/metrics/_classification.py:1731: UndefinedMetricWarning: Precision is ill-defined and being set to 0.0 in labels with no predicted samples. Use `zero_division` parameter to control this behavior.\n",
|
||
|
|
" _warn_prf(average, modifier, f\"{metric.capitalize()} is\", result.shape[0])\n",
|
||
|
|
"/home/nvidia/miniconda3/envs/rapids-25.10/lib/python3.12/site-packages/sklearn/metrics/_classification.py:1731: UndefinedMetricWarning: Precision is ill-defined and being set to 0.0 in labels with no predicted samples. Use `zero_division` parameter to control this behavior.\n",
|
||
|
|
" _warn_prf(average, modifier, f\"{metric.capitalize()} is\", result.shape[0])\n",
|
||
|
|
"/home/nvidia/miniconda3/envs/rapids-25.10/lib/python3.12/site-packages/sklearn/metrics/_classification.py:1731: UndefinedMetricWarning: Precision is ill-defined and being set to 0.0 in labels with no predicted samples. Use `zero_division` parameter to control this behavior.\n",
|
||
|
|
" _warn_prf(average, modifier, f\"{metric.capitalize()} is\", result.shape[0])\n"
|
||
|
|
]
|
||
|
|
}
|
||
|
|
],
|
||
|
|
"source": [
|
||
|
|
"\n",
|
||
|
|
"print(classification_report(y_test, y_pred))"
|
||
|
|
]
|
||
|
|
},
|
||
|
|
{
|
||
|
|
"cell_type": "markdown",
|
||
|
|
"metadata": {},
|
||
|
|
"source": [
|
||
|
|
"With scikit-learn, we built a model that was able to be trained in just a couple minutes. From the accuracy report, we can see that we predicted the correct class around 70% of the time, which is not bad but could certainly be improved.\n",
|
||
|
|
"\n",
|
||
|
|
"Often we want to run several different random forest models in order to optimize our hyperparameters. For example, we may want to increase the number of estimators, or modify the maximum depth of our tree. When running dozens or hundreds of different hyperparameter combinations, things start to become quite slow and iteration takes a lot longer.\n",
|
||
|
|
"\n",
|
||
|
|
"We provide some sample code utilizing GridSearchCV below to show what this process might look like. All of these combinations would take a LONG time to run if we spend 2 minutes fitting each model."
|
||
|
|
]
|
||
|
|
},
|
||
|
|
{
|
||
|
|
"cell_type": "code",
|
||
|
|
"execution_count": 12,
|
||
|
|
"metadata": {},
|
||
|
|
"outputs": [
|
||
|
|
{
|
||
|
|
"data": {
|
||
|
|
"text/plain": [
|
||
|
|
"\"\\nfrom sklearn.model_selection import GridSearchCV\\n\\n# Define the parameter grid to search over\\nparam_grid = {\\n 'n_estimators': [50, 100, 200],\\n 'max_depth': [None, 10, 20, 30],\\n 'min_samples_split': [2, 5, 10],\\n 'min_samples_leaf': [1, 2, 4],\\n 'max_features': ['auto', 'sqrt', 'log2'],\\n 'bootstrap': [True, False]\\n}\\n\\ngrid_search = GridSearchCV(estimator=clf, param_grid=param_grid, cv=5)\\ngrid_search.fit(X_train, y_train)\\n\""
|
||
|
|
]
|
||
|
|
},
|
||
|
|
"execution_count": 12,
|
||
|
|
"metadata": {},
|
||
|
|
"output_type": "execute_result"
|
||
|
|
}
|
||
|
|
],
|
||
|
|
"source": [
|
||
|
|
"\"\"\"\n",
|
||
|
|
"from sklearn.model_selection import GridSearchCV\n",
|
||
|
|
"\n",
|
||
|
|
"# Define the parameter grid to search over\n",
|
||
|
|
"param_grid = {\n",
|
||
|
|
" 'n_estimators': [50, 100, 200],\n",
|
||
|
|
" 'max_depth': [None, 10, 20, 30],\n",
|
||
|
|
" 'min_samples_split': [2, 5, 10],\n",
|
||
|
|
" 'min_samples_leaf': [1, 2, 4],\n",
|
||
|
|
" 'max_features': ['auto', 'sqrt', 'log2'],\n",
|
||
|
|
" 'bootstrap': [True, False]\n",
|
||
|
|
"}\n",
|
||
|
|
"\n",
|
||
|
|
"grid_search = GridSearchCV(estimator=clf, param_grid=param_grid, cv=5)\n",
|
||
|
|
"grid_search.fit(X_train, y_train)\n",
|
||
|
|
"\"\"\""
|
||
|
|
]
|
||
|
|
},
|
||
|
|
{
|
||
|
|
"cell_type": "markdown",
|
||
|
|
"metadata": {},
|
||
|
|
"source": [
|
||
|
|
"With a model that runs in just seconds, we can perform hyperparameter optimization using a method like the grid search shown above, and have results in just minutes instead of hours."
|
||
|
|
]
|
||
|
|
},
|
||
|
|
{
|
||
|
|
"cell_type": "markdown",
|
||
|
|
"metadata": {},
|
||
|
|
"source": [
|
||
|
|
"# CPU Fallback"
|
||
|
|
]
|
||
|
|
},
|
||
|
|
{
|
||
|
|
"cell_type": "markdown",
|
||
|
|
"metadata": {},
|
||
|
|
"source": [
|
||
|
|
"There are some algorithms and functionality from scikit-learn, UMAP, and HDBSCAN that are *not* implemented in cuML. For cases where the underlying functionality is not supported on GPU, the cuML accelerator will gracefully fall back and execute on the CPU instead."
|
||
|
|
]
|
||
|
|
},
|
||
|
|
{
|
||
|
|
"cell_type": "code",
|
||
|
|
"execution_count": 13,
|
||
|
|
"metadata": {},
|
||
|
|
"outputs": [],
|
||
|
|
"source": [
|
||
|
|
"from sklearn.neighbors import KernelDensity\n",
|
||
|
|
"import numpy as np\n",
|
||
|
|
"\n",
|
||
|
|
"X = np.concatenate((np.random.normal(0, 1, 10000),\n",
|
||
|
|
" np.random.normal(5, 1, 10000)))[:, np.newaxis]"
|
||
|
|
]
|
||
|
|
},
|
||
|
|
{
|
||
|
|
"cell_type": "code",
|
||
|
|
"execution_count": null,
|
||
|
|
"metadata": {},
|
||
|
|
"outputs": [
|
||
|
|
{
|
||
|
|
"data": {
|
||
|
|
"text/html": [
|
||
|
|
"<style>#sk-container-id-2 {\n",
|
||
|
|
" /* Definition of color scheme common for light and dark mode */\n",
|
||
|
|
" --sklearn-color-text: #000;\n",
|
||
|
|
" --sklearn-color-text-muted: #666;\n",
|
||
|
|
" --sklearn-color-line: gray;\n",
|
||
|
|
" /* Definition of color scheme for unfitted estimators */\n",
|
||
|
|
" --sklearn-color-unfitted-level-0: #fff5e6;\n",
|
||
|
|
" --sklearn-color-unfitted-level-1: #f6e4d2;\n",
|
||
|
|
" --sklearn-color-unfitted-level-2: #ffe0b3;\n",
|
||
|
|
" --sklearn-color-unfitted-level-3: chocolate;\n",
|
||
|
|
" /* Definition of color scheme for fitted estimators */\n",
|
||
|
|
" --sklearn-color-fitted-level-0: #f0f8ff;\n",
|
||
|
|
" --sklearn-color-fitted-level-1: #d4ebff;\n",
|
||
|
|
" --sklearn-color-fitted-level-2: #b3dbfd;\n",
|
||
|
|
" --sklearn-color-fitted-level-3: cornflowerblue;\n",
|
||
|
|
"\n",
|
||
|
|
" /* Specific color for light theme */\n",
|
||
|
|
" --sklearn-color-text-on-default-background: var(--sg-text-color, var(--theme-code-foreground, var(--jp-content-font-color1, black)));\n",
|
||
|
|
" --sklearn-color-background: var(--sg-background-color, var(--theme-background, var(--jp-layout-color0, white)));\n",
|
||
|
|
" --sklearn-color-border-box: var(--sg-text-color, var(--theme-code-foreground, var(--jp-content-font-color1, black)));\n",
|
||
|
|
" --sklearn-color-icon: #696969;\n",
|
||
|
|
"\n",
|
||
|
|
" @media (prefers-color-scheme: dark) {\n",
|
||
|
|
" /* Redefinition of color scheme for dark theme */\n",
|
||
|
|
" --sklearn-color-text-on-default-background: var(--sg-text-color, var(--theme-code-foreground, var(--jp-content-font-color1, white)));\n",
|
||
|
|
" --sklearn-color-background: var(--sg-background-color, var(--theme-background, var(--jp-layout-color0, #111)));\n",
|
||
|
|
" --sklearn-color-border-box: var(--sg-text-color, var(--theme-code-foreground, var(--jp-content-font-color1, white)));\n",
|
||
|
|
" --sklearn-color-icon: #878787;\n",
|
||
|
|
" }\n",
|
||
|
|
"}\n",
|
||
|
|
"\n",
|
||
|
|
"#sk-container-id-2 {\n",
|
||
|
|
" color: var(--sklearn-color-text);\n",
|
||
|
|
"}\n",
|
||
|
|
"\n",
|
||
|
|
"#sk-container-id-2 pre {\n",
|
||
|
|
" padding: 0;\n",
|
||
|
|
"}\n",
|
||
|
|
"\n",
|
||
|
|
"#sk-container-id-2 input.sk-hidden--visually {\n",
|
||
|
|
" border: 0;\n",
|
||
|
|
" clip: rect(1px 1px 1px 1px);\n",
|
||
|
|
" clip: rect(1px, 1px, 1px, 1px);\n",
|
||
|
|
" height: 1px;\n",
|
||
|
|
" margin: -1px;\n",
|
||
|
|
" overflow: hidden;\n",
|
||
|
|
" padding: 0;\n",
|
||
|
|
" position: absolute;\n",
|
||
|
|
" width: 1px;\n",
|
||
|
|
"}\n",
|
||
|
|
"\n",
|
||
|
|
"#sk-container-id-2 div.sk-dashed-wrapped {\n",
|
||
|
|
" border: 1px dashed var(--sklearn-color-line);\n",
|
||
|
|
" margin: 0 0.4em 0.5em 0.4em;\n",
|
||
|
|
" box-sizing: border-box;\n",
|
||
|
|
" padding-bottom: 0.4em;\n",
|
||
|
|
" background-color: var(--sklearn-color-background);\n",
|
||
|
|
"}\n",
|
||
|
|
"\n",
|
||
|
|
"#sk-container-id-2 div.sk-container {\n",
|
||
|
|
" /* jupyter's `normalize.less` sets `[hidden] { display: none; }`\n",
|
||
|
|
" but bootstrap.min.css set `[hidden] { display: none !important; }`\n",
|
||
|
|
" so we also need the `!important` here to be able to override the\n",
|
||
|
|
" default hidden behavior on the sphinx rendered scikit-learn.org.\n",
|
||
|
|
" See: https://github.com/scikit-learn/scikit-learn/issues/21755 */\n",
|
||
|
|
" display: inline-block !important;\n",
|
||
|
|
" position: relative;\n",
|
||
|
|
"}\n",
|
||
|
|
"\n",
|
||
|
|
"#sk-container-id-2 div.sk-text-repr-fallback {\n",
|
||
|
|
" display: none;\n",
|
||
|
|
"}\n",
|
||
|
|
"\n",
|
||
|
|
"div.sk-parallel-item,\n",
|
||
|
|
"div.sk-serial,\n",
|
||
|
|
"div.sk-item {\n",
|
||
|
|
" /* draw centered vertical line to link estimators */\n",
|
||
|
|
" background-image: linear-gradient(var(--sklearn-color-text-on-default-background), var(--sklearn-color-text-on-default-background));\n",
|
||
|
|
" background-size: 2px 100%;\n",
|
||
|
|
" background-repeat: no-repeat;\n",
|
||
|
|
" background-position: center center;\n",
|
||
|
|
"}\n",
|
||
|
|
"\n",
|
||
|
|
"/* Parallel-specific style estimator block */\n",
|
||
|
|
"\n",
|
||
|
|
"#sk-container-id-2 div.sk-parallel-item::after {\n",
|
||
|
|
" content: \"\";\n",
|
||
|
|
" width: 100%;\n",
|
||
|
|
" border-bottom: 2px solid var(--sklearn-color-text-on-default-background);\n",
|
||
|
|
" flex-grow: 1;\n",
|
||
|
|
"}\n",
|
||
|
|
"\n",
|
||
|
|
"#sk-container-id-2 div.sk-parallel {\n",
|
||
|
|
" display: flex;\n",
|
||
|
|
" align-items: stretch;\n",
|
||
|
|
" justify-content: center;\n",
|
||
|
|
" background-color: var(--sklearn-color-background);\n",
|
||
|
|
" position: relative;\n",
|
||
|
|
"}\n",
|
||
|
|
"\n",
|
||
|
|
"#sk-container-id-2 div.sk-parallel-item {\n",
|
||
|
|
" display: flex;\n",
|
||
|
|
" flex-direction: column;\n",
|
||
|
|
"}\n",
|
||
|
|
"\n",
|
||
|
|
"#sk-container-id-2 div.sk-parallel-item:first-child::after {\n",
|
||
|
|
" align-self: flex-end;\n",
|
||
|
|
" width: 50%;\n",
|
||
|
|
"}\n",
|
||
|
|
"\n",
|
||
|
|
"#sk-container-id-2 div.sk-parallel-item:last-child::after {\n",
|
||
|
|
" align-self: flex-start;\n",
|
||
|
|
" width: 50%;\n",
|
||
|
|
"}\n",
|
||
|
|
"\n",
|
||
|
|
"#sk-container-id-2 div.sk-parallel-item:only-child::after {\n",
|
||
|
|
" width: 0;\n",
|
||
|
|
"}\n",
|
||
|
|
"\n",
|
||
|
|
"/* Serial-specific style estimator block */\n",
|
||
|
|
"\n",
|
||
|
|
"#sk-container-id-2 div.sk-serial {\n",
|
||
|
|
" display: flex;\n",
|
||
|
|
" flex-direction: column;\n",
|
||
|
|
" align-items: center;\n",
|
||
|
|
" background-color: var(--sklearn-color-background);\n",
|
||
|
|
" padding-right: 1em;\n",
|
||
|
|
" padding-left: 1em;\n",
|
||
|
|
"}\n",
|
||
|
|
"\n",
|
||
|
|
"\n",
|
||
|
|
"/* Toggleable style: style used for estimator/Pipeline/ColumnTransformer box that is\n",
|
||
|
|
"clickable and can be expanded/collapsed.\n",
|
||
|
|
"- Pipeline and ColumnTransformer use this feature and define the default style\n",
|
||
|
|
"- Estimators will overwrite some part of the style using the `sk-estimator` class\n",
|
||
|
|
"*/\n",
|
||
|
|
"\n",
|
||
|
|
"/* Pipeline and ColumnTransformer style (default) */\n",
|
||
|
|
"\n",
|
||
|
|
"#sk-container-id-2 div.sk-toggleable {\n",
|
||
|
|
" /* Default theme specific background. It is overwritten whether we have a\n",
|
||
|
|
" specific estimator or a Pipeline/ColumnTransformer */\n",
|
||
|
|
" background-color: var(--sklearn-color-background);\n",
|
||
|
|
"}\n",
|
||
|
|
"\n",
|
||
|
|
"/* Toggleable label */\n",
|
||
|
|
"#sk-container-id-2 label.sk-toggleable__label {\n",
|
||
|
|
" cursor: pointer;\n",
|
||
|
|
" display: flex;\n",
|
||
|
|
" width: 100%;\n",
|
||
|
|
" margin-bottom: 0;\n",
|
||
|
|
" padding: 0.5em;\n",
|
||
|
|
" box-sizing: border-box;\n",
|
||
|
|
" text-align: center;\n",
|
||
|
|
" align-items: start;\n",
|
||
|
|
" justify-content: space-between;\n",
|
||
|
|
" gap: 0.5em;\n",
|
||
|
|
"}\n",
|
||
|
|
"\n",
|
||
|
|
"#sk-container-id-2 label.sk-toggleable__label .caption {\n",
|
||
|
|
" font-size: 0.6rem;\n",
|
||
|
|
" font-weight: lighter;\n",
|
||
|
|
" color: var(--sklearn-color-text-muted);\n",
|
||
|
|
"}\n",
|
||
|
|
"\n",
|
||
|
|
"#sk-container-id-2 label.sk-toggleable__label-arrow:before {\n",
|
||
|
|
" /* Arrow on the left of the label */\n",
|
||
|
|
" content: \"▸\";\n",
|
||
|
|
" float: left;\n",
|
||
|
|
" margin-right: 0.25em;\n",
|
||
|
|
" color: var(--sklearn-color-icon);\n",
|
||
|
|
"}\n",
|
||
|
|
"\n",
|
||
|
|
"#sk-container-id-2 label.sk-toggleable__label-arrow:hover:before {\n",
|
||
|
|
" color: var(--sklearn-color-text);\n",
|
||
|
|
"}\n",
|
||
|
|
"\n",
|
||
|
|
"/* Toggleable content - dropdown */\n",
|
||
|
|
"\n",
|
||
|
|
"#sk-container-id-2 div.sk-toggleable__content {\n",
|
||
|
|
" display: none;\n",
|
||
|
|
" text-align: left;\n",
|
||
|
|
" /* unfitted */\n",
|
||
|
|
" background-color: var(--sklearn-color-unfitted-level-0);\n",
|
||
|
|
"}\n",
|
||
|
|
"\n",
|
||
|
|
"#sk-container-id-2 div.sk-toggleable__content.fitted {\n",
|
||
|
|
" /* fitted */\n",
|
||
|
|
" background-color: var(--sklearn-color-fitted-level-0);\n",
|
||
|
|
"}\n",
|
||
|
|
"\n",
|
||
|
|
"#sk-container-id-2 div.sk-toggleable__content pre {\n",
|
||
|
|
" margin: 0.2em;\n",
|
||
|
|
" border-radius: 0.25em;\n",
|
||
|
|
" color: var(--sklearn-color-text);\n",
|
||
|
|
" /* unfitted */\n",
|
||
|
|
" background-color: var(--sklearn-color-unfitted-level-0);\n",
|
||
|
|
"}\n",
|
||
|
|
"\n",
|
||
|
|
"#sk-container-id-2 div.sk-toggleable__content.fitted pre {\n",
|
||
|
|
" /* unfitted */\n",
|
||
|
|
" background-color: var(--sklearn-color-fitted-level-0);\n",
|
||
|
|
"}\n",
|
||
|
|
"\n",
|
||
|
|
"#sk-container-id-2 input.sk-toggleable__control:checked~div.sk-toggleable__content {\n",
|
||
|
|
" /* Expand drop-down */\n",
|
||
|
|
" display: block;\n",
|
||
|
|
" width: 100%;\n",
|
||
|
|
" overflow: visible;\n",
|
||
|
|
"}\n",
|
||
|
|
"\n",
|
||
|
|
"#sk-container-id-2 input.sk-toggleable__control:checked~label.sk-toggleable__label-arrow:before {\n",
|
||
|
|
" content: \"▾\";\n",
|
||
|
|
"}\n",
|
||
|
|
"\n",
|
||
|
|
"/* Pipeline/ColumnTransformer-specific style */\n",
|
||
|
|
"\n",
|
||
|
|
"#sk-container-id-2 div.sk-label input.sk-toggleable__control:checked~label.sk-toggleable__label {\n",
|
||
|
|
" color: var(--sklearn-color-text);\n",
|
||
|
|
" background-color: var(--sklearn-color-unfitted-level-2);\n",
|
||
|
|
"}\n",
|
||
|
|
"\n",
|
||
|
|
"#sk-container-id-2 div.sk-label.fitted input.sk-toggleable__control:checked~label.sk-toggleable__label {\n",
|
||
|
|
" background-color: var(--sklearn-color-fitted-level-2);\n",
|
||
|
|
"}\n",
|
||
|
|
"\n",
|
||
|
|
"/* Estimator-specific style */\n",
|
||
|
|
"\n",
|
||
|
|
"/* Colorize estimator box */\n",
|
||
|
|
"#sk-container-id-2 div.sk-estimator input.sk-toggleable__control:checked~label.sk-toggleable__label {\n",
|
||
|
|
" /* unfitted */\n",
|
||
|
|
" background-color: var(--sklearn-color-unfitted-level-2);\n",
|
||
|
|
"}\n",
|
||
|
|
"\n",
|
||
|
|
"#sk-container-id-2 div.sk-estimator.fitted input.sk-toggleable__control:checked~label.sk-toggleable__label {\n",
|
||
|
|
" /* fitted */\n",
|
||
|
|
" background-color: var(--sklearn-color-fitted-level-2);\n",
|
||
|
|
"}\n",
|
||
|
|
"\n",
|
||
|
|
"#sk-container-id-2 div.sk-label label.sk-toggleable__label,\n",
|
||
|
|
"#sk-container-id-2 div.sk-label label {\n",
|
||
|
|
" /* The background is the default theme color */\n",
|
||
|
|
" color: var(--sklearn-color-text-on-default-background);\n",
|
||
|
|
"}\n",
|
||
|
|
"\n",
|
||
|
|
"/* On hover, darken the color of the background */\n",
|
||
|
|
"#sk-container-id-2 div.sk-label:hover label.sk-toggleable__label {\n",
|
||
|
|
" color: var(--sklearn-color-text);\n",
|
||
|
|
" background-color: var(--sklearn-color-unfitted-level-2);\n",
|
||
|
|
"}\n",
|
||
|
|
"\n",
|
||
|
|
"/* Label box, darken color on hover, fitted */\n",
|
||
|
|
"#sk-container-id-2 div.sk-label.fitted:hover label.sk-toggleable__label.fitted {\n",
|
||
|
|
" color: var(--sklearn-color-text);\n",
|
||
|
|
" background-color: var(--sklearn-color-fitted-level-2);\n",
|
||
|
|
"}\n",
|
||
|
|
"\n",
|
||
|
|
"/* Estimator label */\n",
|
||
|
|
"\n",
|
||
|
|
"#sk-container-id-2 div.sk-label label {\n",
|
||
|
|
" font-family: monospace;\n",
|
||
|
|
" font-weight: bold;\n",
|
||
|
|
" display: inline-block;\n",
|
||
|
|
" line-height: 1.2em;\n",
|
||
|
|
"}\n",
|
||
|
|
"\n",
|
||
|
|
"#sk-container-id-2 div.sk-label-container {\n",
|
||
|
|
" text-align: center;\n",
|
||
|
|
"}\n",
|
||
|
|
"\n",
|
||
|
|
"/* Estimator-specific */\n",
|
||
|
|
"#sk-container-id-2 div.sk-estimator {\n",
|
||
|
|
" font-family: monospace;\n",
|
||
|
|
" border: 1px dotted var(--sklearn-color-border-box);\n",
|
||
|
|
" border-radius: 0.25em;\n",
|
||
|
|
" box-sizing: border-box;\n",
|
||
|
|
" margin-bottom: 0.5em;\n",
|
||
|
|
" /* unfitted */\n",
|
||
|
|
" background-color: var(--sklearn-color-unfitted-level-0);\n",
|
||
|
|
"}\n",
|
||
|
|
"\n",
|
||
|
|
"#sk-container-id-2 div.sk-estimator.fitted {\n",
|
||
|
|
" /* fitted */\n",
|
||
|
|
" background-color: var(--sklearn-color-fitted-level-0);\n",
|
||
|
|
"}\n",
|
||
|
|
"\n",
|
||
|
|
"/* on hover */\n",
|
||
|
|
"#sk-container-id-2 div.sk-estimator:hover {\n",
|
||
|
|
" /* unfitted */\n",
|
||
|
|
" background-color: var(--sklearn-color-unfitted-level-2);\n",
|
||
|
|
"}\n",
|
||
|
|
"\n",
|
||
|
|
"#sk-container-id-2 div.sk-estimator.fitted:hover {\n",
|
||
|
|
" /* fitted */\n",
|
||
|
|
" background-color: var(--sklearn-color-fitted-level-2);\n",
|
||
|
|
"}\n",
|
||
|
|
"\n",
|
||
|
|
"/* Specification for estimator info (e.g. \"i\" and \"?\") */\n",
|
||
|
|
"\n",
|
||
|
|
"/* Common style for \"i\" and \"?\" */\n",
|
||
|
|
"\n",
|
||
|
|
".sk-estimator-doc-link,\n",
|
||
|
|
"a:link.sk-estimator-doc-link,\n",
|
||
|
|
"a:visited.sk-estimator-doc-link {\n",
|
||
|
|
" float: right;\n",
|
||
|
|
" font-size: smaller;\n",
|
||
|
|
" line-height: 1em;\n",
|
||
|
|
" font-family: monospace;\n",
|
||
|
|
" background-color: var(--sklearn-color-background);\n",
|
||
|
|
" border-radius: 1em;\n",
|
||
|
|
" height: 1em;\n",
|
||
|
|
" width: 1em;\n",
|
||
|
|
" text-decoration: none !important;\n",
|
||
|
|
" margin-left: 0.5em;\n",
|
||
|
|
" text-align: center;\n",
|
||
|
|
" /* unfitted */\n",
|
||
|
|
" border: var(--sklearn-color-unfitted-level-1) 1pt solid;\n",
|
||
|
|
" color: var(--sklearn-color-unfitted-level-1);\n",
|
||
|
|
"}\n",
|
||
|
|
"\n",
|
||
|
|
".sk-estimator-doc-link.fitted,\n",
|
||
|
|
"a:link.sk-estimator-doc-link.fitted,\n",
|
||
|
|
"a:visited.sk-estimator-doc-link.fitted {\n",
|
||
|
|
" /* fitted */\n",
|
||
|
|
" border: var(--sklearn-color-fitted-level-1) 1pt solid;\n",
|
||
|
|
" color: var(--sklearn-color-fitted-level-1);\n",
|
||
|
|
"}\n",
|
||
|
|
"\n",
|
||
|
|
"/* On hover */\n",
|
||
|
|
"div.sk-estimator:hover .sk-estimator-doc-link:hover,\n",
|
||
|
|
".sk-estimator-doc-link:hover,\n",
|
||
|
|
"div.sk-label-container:hover .sk-estimator-doc-link:hover,\n",
|
||
|
|
".sk-estimator-doc-link:hover {\n",
|
||
|
|
" /* unfitted */\n",
|
||
|
|
" background-color: var(--sklearn-color-unfitted-level-3);\n",
|
||
|
|
" color: var(--sklearn-color-background);\n",
|
||
|
|
" text-decoration: none;\n",
|
||
|
|
"}\n",
|
||
|
|
"\n",
|
||
|
|
"div.sk-estimator.fitted:hover .sk-estimator-doc-link.fitted:hover,\n",
|
||
|
|
".sk-estimator-doc-link.fitted:hover,\n",
|
||
|
|
"div.sk-label-container:hover .sk-estimator-doc-link.fitted:hover,\n",
|
||
|
|
".sk-estimator-doc-link.fitted:hover {\n",
|
||
|
|
" /* fitted */\n",
|
||
|
|
" background-color: var(--sklearn-color-fitted-level-3);\n",
|
||
|
|
" color: var(--sklearn-color-background);\n",
|
||
|
|
" text-decoration: none;\n",
|
||
|
|
"}\n",
|
||
|
|
"\n",
|
||
|
|
"/* Span, style for the box shown on hovering the info icon */\n",
|
||
|
|
".sk-estimator-doc-link span {\n",
|
||
|
|
" display: none;\n",
|
||
|
|
" z-index: 9999;\n",
|
||
|
|
" position: relative;\n",
|
||
|
|
" font-weight: normal;\n",
|
||
|
|
" right: .2ex;\n",
|
||
|
|
" padding: .5ex;\n",
|
||
|
|
" margin: .5ex;\n",
|
||
|
|
" width: min-content;\n",
|
||
|
|
" min-width: 20ex;\n",
|
||
|
|
" max-width: 50ex;\n",
|
||
|
|
" color: var(--sklearn-color-text);\n",
|
||
|
|
" box-shadow: 2pt 2pt 4pt #999;\n",
|
||
|
|
" /* unfitted */\n",
|
||
|
|
" background: var(--sklearn-color-unfitted-level-0);\n",
|
||
|
|
" border: .5pt solid var(--sklearn-color-unfitted-level-3);\n",
|
||
|
|
"}\n",
|
||
|
|
"\n",
|
||
|
|
".sk-estimator-doc-link.fitted span {\n",
|
||
|
|
" /* fitted */\n",
|
||
|
|
" background: var(--sklearn-color-fitted-level-0);\n",
|
||
|
|
" border: var(--sklearn-color-fitted-level-3);\n",
|
||
|
|
"}\n",
|
||
|
|
"\n",
|
||
|
|
".sk-estimator-doc-link:hover span {\n",
|
||
|
|
" display: block;\n",
|
||
|
|
"}\n",
|
||
|
|
"\n",
|
||
|
|
"/* \"?\"-specific style due to the `<a>` HTML tag */\n",
|
||
|
|
"\n",
|
||
|
|
"#sk-container-id-2 a.estimator_doc_link {\n",
|
||
|
|
" float: right;\n",
|
||
|
|
" font-size: 1rem;\n",
|
||
|
|
" line-height: 1em;\n",
|
||
|
|
" font-family: monospace;\n",
|
||
|
|
" background-color: var(--sklearn-color-background);\n",
|
||
|
|
" border-radius: 1rem;\n",
|
||
|
|
" height: 1rem;\n",
|
||
|
|
" width: 1rem;\n",
|
||
|
|
" text-decoration: none;\n",
|
||
|
|
" /* unfitted */\n",
|
||
|
|
" color: var(--sklearn-color-unfitted-level-1);\n",
|
||
|
|
" border: var(--sklearn-color-unfitted-level-1) 1pt solid;\n",
|
||
|
|
"}\n",
|
||
|
|
"\n",
|
||
|
|
"#sk-container-id-2 a.estimator_doc_link.fitted {\n",
|
||
|
|
" /* fitted */\n",
|
||
|
|
" border: var(--sklearn-color-fitted-level-1) 1pt solid;\n",
|
||
|
|
" color: var(--sklearn-color-fitted-level-1);\n",
|
||
|
|
"}\n",
|
||
|
|
"\n",
|
||
|
|
"/* On hover */\n",
|
||
|
|
"#sk-container-id-2 a.estimator_doc_link:hover {\n",
|
||
|
|
" /* unfitted */\n",
|
||
|
|
" background-color: var(--sklearn-color-unfitted-level-3);\n",
|
||
|
|
" color: var(--sklearn-color-background);\n",
|
||
|
|
" text-decoration: none;\n",
|
||
|
|
"}\n",
|
||
|
|
"\n",
|
||
|
|
"#sk-container-id-2 a.estimator_doc_link.fitted:hover {\n",
|
||
|
|
" /* fitted */\n",
|
||
|
|
" background-color: var(--sklearn-color-fitted-level-3);\n",
|
||
|
|
"}\n",
|
||
|
|
"\n",
|
||
|
|
".estimator-table summary {\n",
|
||
|
|
" padding: .5rem;\n",
|
||
|
|
" font-family: monospace;\n",
|
||
|
|
" cursor: pointer;\n",
|
||
|
|
"}\n",
|
||
|
|
"\n",
|
||
|
|
".estimator-table details[open] {\n",
|
||
|
|
" padding-left: 0.1rem;\n",
|
||
|
|
" padding-right: 0.1rem;\n",
|
||
|
|
" padding-bottom: 0.3rem;\n",
|
||
|
|
"}\n",
|
||
|
|
"\n",
|
||
|
|
".estimator-table .parameters-table {\n",
|
||
|
|
" margin-left: auto !important;\n",
|
||
|
|
" margin-right: auto !important;\n",
|
||
|
|
"}\n",
|
||
|
|
"\n",
|
||
|
|
".estimator-table .parameters-table tr:nth-child(odd) {\n",
|
||
|
|
" background-color: #fff;\n",
|
||
|
|
"}\n",
|
||
|
|
"\n",
|
||
|
|
".estimator-table .parameters-table tr:nth-child(even) {\n",
|
||
|
|
" background-color: #f6f6f6;\n",
|
||
|
|
"}\n",
|
||
|
|
"\n",
|
||
|
|
".estimator-table .parameters-table tr:hover {\n",
|
||
|
|
" background-color: #e0e0e0;\n",
|
||
|
|
"}\n",
|
||
|
|
"\n",
|
||
|
|
".estimator-table table td {\n",
|
||
|
|
" border: 1px solid rgba(106, 105, 104, 0.232);\n",
|
||
|
|
"}\n",
|
||
|
|
"\n",
|
||
|
|
".user-set td {\n",
|
||
|
|
" color:rgb(255, 94, 0);\n",
|
||
|
|
" text-align: left;\n",
|
||
|
|
"}\n",
|
||
|
|
"\n",
|
||
|
|
".user-set td.value pre {\n",
|
||
|
|
" color:rgb(255, 94, 0) !important;\n",
|
||
|
|
" background-color: transparent !important;\n",
|
||
|
|
"}\n",
|
||
|
|
"\n",
|
||
|
|
".default td {\n",
|
||
|
|
" color: black;\n",
|
||
|
|
" text-align: left;\n",
|
||
|
|
"}\n",
|
||
|
|
"\n",
|
||
|
|
".user-set td i,\n",
|
||
|
|
".default td i {\n",
|
||
|
|
" color: black;\n",
|
||
|
|
"}\n",
|
||
|
|
"\n",
|
||
|
|
".copy-paste-icon {\n",
|
||
|
|
" background-image: url(data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHZpZXdCb3g9IjAgMCA0NDggNTEyIj48IS0tIUZvbnQgQXdlc29tZSBGcmVlIDYuNy4yIGJ5IEBmb250YXdlc29tZSAtIGh0dHBzOi8vZm9udGF3ZXNvbWUuY29tIExpY2Vuc2UgLSBodHRwczovL2ZvbnRhd2Vzb21lLmNvbS9saWNlbnNlL2ZyZWUgQ29weXJpZ2h0IDIwMjUgRm9udGljb25zLCBJbmMuLS0+PHBhdGggZD0iTTIwOCAwTDMzMi4xIDBjMTIuNyAwIDI0LjkgNS4xIDMzLjkgMTQuMWw2Ny45IDY3LjljOSA5IDE0LjEgMjEuMiAxNC4xIDMzLjlMNDQ4IDMzNmMwIDI2LjUtMjEuNSA0OC00OCA0OGwtMTkyIDBjLTI2LjUgMC00OC0yMS41LTQ4LTQ4bDAtMjg4YzAtMjYuNSAyMS41LTQ4IDQ4LTQ4ek00OCAxMjhsODAgMCAwIDY0LTY0IDAgMCAyNTYgMTkyIDAgMC0zMiA2NCAwIDAgNDhjMCAyNi41LTIxLjUgNDgtNDggNDhMNDggNTEyYy0yNi41IDAtNDgtMjEuNS00OC00OEwwIDE3NmMwLTI2LjUgMjEuNS00OCA0OC00OHoiLz48L3N2Zz4=);\n",
|
||
|
|
" background-repeat: no-repeat;\n",
|
||
|
|
" background-size: 14px 14px;\n",
|
||
|
|
" background-position: 0;\n",
|
||
|
|
" display: inline-block;\n",
|
||
|
|
" width: 14px;\n",
|
||
|
|
" height: 14px;\n",
|
||
|
|
" cursor: pointer;\n",
|
||
|
|
"}\n",
|
||
|
|
"</style><body><div id=\"sk-container-id-2\" class=\"sk-top-container\"><div class=\"sk-text-repr-fallback\"><pre>KernelDensity(bandwidth=0.5)</pre><b>In a Jupyter environment, please rerun this cell to show the HTML representation or trust the notebook. <br />On GitHub, the HTML representation is unable to render, please try loading this page with nbviewer.org.</b></div><div class=\"sk-container\" hidden><div class=\"sk-item\"><div class=\"sk-estimator fitted sk-toggleable\"><input class=\"sk-toggleable__control sk-hidden--visually\" id=\"sk-estimator-id-2\" type=\"checkbox\" checked><label for=\"sk-estimator-id-2\" class=\"sk-toggleable__label fitted sk-toggleable__label-arrow\"><div><div>KernelDensity</div></div><div><a class=\"sk-estimator-doc-link fitted\" rel=\"noreferrer\" target=\"_blank\" href=\"https://scikit-learn.org/1.7/modules/generated/sklearn.neighbors.KernelDensity.html\">?<span>Documentation for KernelDensity</span></a><span class=\"sk-estimator-doc-link fitted\">i<span>Fitted</span></span></div></label><div class=\"sk-toggleable__content fitted\" data-param-prefix=\"\">\n",
|
||
|
|
" <div class=\"estimator-table\">\n",
|
||
|
|
" <details>\n",
|
||
|
|
" <summary>Parameters</summary>\n",
|
||
|
|
" <table class=\"parameters-table\">\n",
|
||
|
|
" <tbody>\n",
|
||
|
|
" \n",
|
||
|
|
" <tr class=\"user-set\">\n",
|
||
|
|
" <td><i class=\"copy-paste-icon\"\n",
|
||
|
|
" onclick=\"copyToClipboard('bandwidth',\n",
|
||
|
|
" this.parentElement.nextElementSibling)\"\n",
|
||
|
|
" ></i></td>\n",
|
||
|
|
" <td class=\"param\">bandwidth </td>\n",
|
||
|
|
" <td class=\"value\">0.5</td>\n",
|
||
|
|
" </tr>\n",
|
||
|
|
" \n",
|
||
|
|
"\n",
|
||
|
|
" <tr class=\"default\">\n",
|
||
|
|
" <td><i class=\"copy-paste-icon\"\n",
|
||
|
|
" onclick=\"copyToClipboard('algorithm',\n",
|
||
|
|
" this.parentElement.nextElementSibling)\"\n",
|
||
|
|
" ></i></td>\n",
|
||
|
|
" <td class=\"param\">algorithm </td>\n",
|
||
|
|
" <td class=\"value\">'auto'</td>\n",
|
||
|
|
" </tr>\n",
|
||
|
|
" \n",
|
||
|
|
"\n",
|
||
|
|
" <tr class=\"default\">\n",
|
||
|
|
" <td><i class=\"copy-paste-icon\"\n",
|
||
|
|
" onclick=\"copyToClipboard('kernel',\n",
|
||
|
|
" this.parentElement.nextElementSibling)\"\n",
|
||
|
|
" ></i></td>\n",
|
||
|
|
" <td class=\"param\">kernel </td>\n",
|
||
|
|
" <td class=\"value\">'gaussian'</td>\n",
|
||
|
|
" </tr>\n",
|
||
|
|
" \n",
|
||
|
|
"\n",
|
||
|
|
" <tr class=\"default\">\n",
|
||
|
|
" <td><i class=\"copy-paste-icon\"\n",
|
||
|
|
" onclick=\"copyToClipboard('metric',\n",
|
||
|
|
" this.parentElement.nextElementSibling)\"\n",
|
||
|
|
" ></i></td>\n",
|
||
|
|
" <td class=\"param\">metric </td>\n",
|
||
|
|
" <td class=\"value\">'euclidean'</td>\n",
|
||
|
|
" </tr>\n",
|
||
|
|
" \n",
|
||
|
|
"\n",
|
||
|
|
" <tr class=\"default\">\n",
|
||
|
|
" <td><i class=\"copy-paste-icon\"\n",
|
||
|
|
" onclick=\"copyToClipboard('atol',\n",
|
||
|
|
" this.parentElement.nextElementSibling)\"\n",
|
||
|
|
" ></i></td>\n",
|
||
|
|
" <td class=\"param\">atol </td>\n",
|
||
|
|
" <td class=\"value\">0</td>\n",
|
||
|
|
" </tr>\n",
|
||
|
|
" \n",
|
||
|
|
"\n",
|
||
|
|
" <tr class=\"default\">\n",
|
||
|
|
" <td><i class=\"copy-paste-icon\"\n",
|
||
|
|
" onclick=\"copyToClipboard('rtol',\n",
|
||
|
|
" this.parentElement.nextElementSibling)\"\n",
|
||
|
|
" ></i></td>\n",
|
||
|
|
" <td class=\"param\">rtol </td>\n",
|
||
|
|
" <td class=\"value\">0</td>\n",
|
||
|
|
" </tr>\n",
|
||
|
|
" \n",
|
||
|
|
"\n",
|
||
|
|
" <tr class=\"default\">\n",
|
||
|
|
" <td><i class=\"copy-paste-icon\"\n",
|
||
|
|
" onclick=\"copyToClipboard('breadth_first',\n",
|
||
|
|
" this.parentElement.nextElementSibling)\"\n",
|
||
|
|
" ></i></td>\n",
|
||
|
|
" <td class=\"param\">breadth_first </td>\n",
|
||
|
|
" <td class=\"value\">True</td>\n",
|
||
|
|
" </tr>\n",
|
||
|
|
" \n",
|
||
|
|
"\n",
|
||
|
|
" <tr class=\"default\">\n",
|
||
|
|
" <td><i class=\"copy-paste-icon\"\n",
|
||
|
|
" onclick=\"copyToClipboard('leaf_size',\n",
|
||
|
|
" this.parentElement.nextElementSibling)\"\n",
|
||
|
|
" ></i></td>\n",
|
||
|
|
" <td class=\"param\">leaf_size </td>\n",
|
||
|
|
" <td class=\"value\">40</td>\n",
|
||
|
|
" </tr>\n",
|
||
|
|
" \n",
|
||
|
|
"\n",
|
||
|
|
" <tr class=\"default\">\n",
|
||
|
|
" <td><i class=\"copy-paste-icon\"\n",
|
||
|
|
" onclick=\"copyToClipboard('metric_params',\n",
|
||
|
|
" this.parentElement.nextElementSibling)\"\n",
|
||
|
|
" ></i></td>\n",
|
||
|
|
" <td class=\"param\">metric_params </td>\n",
|
||
|
|
" <td class=\"value\">None</td>\n",
|
||
|
|
" </tr>\n",
|
||
|
|
" \n",
|
||
|
|
" </tbody>\n",
|
||
|
|
" </table>\n",
|
||
|
|
" </details>\n",
|
||
|
|
" </div>\n",
|
||
|
|
" </div></div></div></div></div><script>function copyToClipboard(text, element) {\n",
|
||
|
|
" // Get the parameter prefix from the closest toggleable content\n",
|
||
|
|
" const toggleableContent = element.closest('.sk-toggleable__content');\n",
|
||
|
|
" const paramPrefix = toggleableContent ? toggleableContent.dataset.paramPrefix : '';\n",
|
||
|
|
" const fullParamName = paramPrefix ? `${paramPrefix}${text}` : text;\n",
|
||
|
|
"\n",
|
||
|
|
" const originalStyle = element.style;\n",
|
||
|
|
" const computedStyle = window.getComputedStyle(element);\n",
|
||
|
|
" const originalWidth = computedStyle.width;\n",
|
||
|
|
" const originalHTML = element.innerHTML.replace('Copied!', '');\n",
|
||
|
|
"\n",
|
||
|
|
" navigator.clipboard.writeText(fullParamName)\n",
|
||
|
|
" .then(() => {\n",
|
||
|
|
" element.style.width = originalWidth;\n",
|
||
|
|
" element.style.color = 'green';\n",
|
||
|
|
" element.innerHTML = \"Copied!\";\n",
|
||
|
|
"\n",
|
||
|
|
" setTimeout(() => {\n",
|
||
|
|
" element.innerHTML = originalHTML;\n",
|
||
|
|
" element.style = originalStyle;\n",
|
||
|
|
" }, 2000);\n",
|
||
|
|
" })\n",
|
||
|
|
" .catch(err => {\n",
|
||
|
|
" console.error('Failed to copy:', err);\n",
|
||
|
|
" element.style.color = 'red';\n",
|
||
|
|
" element.innerHTML = \"Failed!\";\n",
|
||
|
|
" setTimeout(() => {\n",
|
||
|
|
" element.innerHTML = originalHTML;\n",
|
||
|
|
" element.style = originalStyle;\n",
|
||
|
|
" }, 2000);\n",
|
||
|
|
" });\n",
|
||
|
|
" return false;\n",
|
||
|
|
"}\n",
|
||
|
|
"\n",
|
||
|
|
"document.querySelectorAll('.fa-regular.fa-copy').forEach(function(element) {\n",
|
||
|
|
" const toggleableContent = element.closest('.sk-toggleable__content');\n",
|
||
|
|
" const paramPrefix = toggleableContent ? toggleableContent.dataset.paramPrefix : '';\n",
|
||
|
|
" const paramName = element.parentElement.nextElementSibling.textContent.trim();\n",
|
||
|
|
" const fullParamName = paramPrefix ? `${paramPrefix}${paramName}` : paramName;\n",
|
||
|
|
"\n",
|
||
|
|
" element.setAttribute('title', fullParamName);\n",
|
||
|
|
"});\n",
|
||
|
|
"</script></body>"
|
||
|
|
],
|
||
|
|
"text/plain": [
|
||
|
|
"KernelDensity(bandwidth=0.5)"
|
||
|
|
]
|
||
|
|
},
|
||
|
|
"execution_count": 14,
|
||
|
|
"metadata": {},
|
||
|
|
"output_type": "execute_result"
|
||
|
|
}
|
||
|
|
],
|
||
|
|
"source": [
|
||
|
|
"%%time\n",
|
||
|
|
"kde = KernelDensity(kernel='gaussian', bandwidth=0.5)\n",
|
||
|
|
"kde.fit(X)"
|
||
|
|
]
|
||
|
|
},
|
||
|
|
{
|
||
|
|
"cell_type": "code",
|
||
|
|
"execution_count": 15,
|
||
|
|
"metadata": {},
|
||
|
|
"outputs": [
|
||
|
|
{
|
||
|
|
"name": "stdout",
|
||
|
|
"output_type": "stream",
|
||
|
|
"text": [
|
||
|
|
"[-2.03555686 -1.81195669 -1.78476911 ... -3.20381041 -1.73643757\n",
|
||
|
|
" -2.82360998]\n"
|
||
|
|
]
|
||
|
|
}
|
||
|
|
],
|
||
|
|
"source": [
|
||
|
|
"print(kde.score_samples(X))"
|
||
|
|
]
|
||
|
|
},
|
||
|
|
{
|
||
|
|
"cell_type": "markdown",
|
||
|
|
"metadata": {
|
||
|
|
"id": "9Ql7UCNUW1AO"
|
||
|
|
},
|
||
|
|
"source": [
|
||
|
|
"We'll now take a look at a clustering example using HDBSCAN."
|
||
|
|
]
|
||
|
|
},
|
||
|
|
{
|
||
|
|
"cell_type": "markdown",
|
||
|
|
"metadata": {
|
||
|
|
"id": "pdjvwlZ-DaoW"
|
||
|
|
},
|
||
|
|
"source": [
|
||
|
|
"# Clustering"
|
||
|
|
]
|
||
|
|
},
|
||
|
|
{
|
||
|
|
"cell_type": "markdown",
|
||
|
|
"metadata": {
|
||
|
|
"id": "70sdcTIdfzkK"
|
||
|
|
},
|
||
|
|
"source": [
|
||
|
|
"Clustering is an important data science workflow because it helps uncover hidden patterns and structures within data without requiring labeled outcomes. In practice, with high dimensional data it can be difficult to discern whether the clusters we've chosen are good or not. One way to determine the quality of our clustering is with sklearn's [silhouette score](https://scikit-learn.org/stable/modules/generated/sklearn.metrics.silhouette_score.html#sklearn.metrics.silhouette_score), which we'll examine shortly.\n",
|
||
|
|
"\n",
|
||
|
|
"HDBSCAN is a popular density-based clustering algorithm that is highly flexible. We'll load a toy sklearn dataset to illustrate how HDBSCAN can be accelerated with cuml.accel."
|
||
|
|
]
|
||
|
|
},
|
||
|
|
{
|
||
|
|
"cell_type": "code",
|
||
|
|
"execution_count": 17,
|
||
|
|
"metadata": {
|
||
|
|
"id": "oIlRPHZ1DZ7q"
|
||
|
|
},
|
||
|
|
"outputs": [],
|
||
|
|
"source": [
|
||
|
|
"import hdbscan\n",
|
||
|
|
"import matplotlib.pyplot as plt\n",
|
||
|
|
"from sklearn.datasets import make_blobs\n",
|
||
|
|
"from sklearn.metrics import silhouette_score"
|
||
|
|
]
|
||
|
|
},
|
||
|
|
{
|
||
|
|
"cell_type": "code",
|
||
|
|
"execution_count": 18,
|
||
|
|
"metadata": {
|
||
|
|
"colab": {
|
||
|
|
"base_uri": "https://localhost:8080/",
|
||
|
|
"height": 449
|
||
|
|
},
|
||
|
|
"id": "RqXkNWRjDZ9n",
|
||
|
|
"outputId": "57435e6c-a303-4531-d64b-87ba14cce410"
|
||
|
|
},
|
||
|
|
"outputs": [
|
||
|
|
{
|
||
|
|
"data": {
|
||
|
|
"text/plain": [
|
||
|
|
"<matplotlib.collections.PathCollection at 0xec601f5865d0>"
|
||
|
|
]
|
||
|
|
},
|
||
|
|
"execution_count": 18,
|
||
|
|
"metadata": {},
|
||
|
|
"output_type": "execute_result"
|
||
|
|
},
|
||
|
|
{
|
||
|
|
"data": {
|
||
|
|
"image/png": "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
|
||
|
|
"text/plain": [
|
||
|
|
"<Figure size 640x480 with 1 Axes>"
|
||
|
|
]
|
||
|
|
},
|
||
|
|
"metadata": {},
|
||
|
|
"output_type": "display_data"
|
||
|
|
}
|
||
|
|
],
|
||
|
|
"source": [
|
||
|
|
"N = 20000\n",
|
||
|
|
"K = 100\n",
|
||
|
|
"\n",
|
||
|
|
"X, y = make_blobs(\n",
|
||
|
|
" n_samples=N,\n",
|
||
|
|
" n_features=K,\n",
|
||
|
|
" centers=5,\n",
|
||
|
|
" cluster_std=[3,1,2,1.5,0.5],\n",
|
||
|
|
" random_state=42\n",
|
||
|
|
")\n",
|
||
|
|
"\n",
|
||
|
|
"plt.scatter(X[:, 0], X[:, 1], c=y)"
|
||
|
|
]
|
||
|
|
},
|
||
|
|
{
|
||
|
|
"cell_type": "code",
|
||
|
|
"execution_count": null,
|
||
|
|
"metadata": {
|
||
|
|
"colab": {
|
||
|
|
"base_uri": "https://localhost:8080/",
|
||
|
|
"height": 184
|
||
|
|
},
|
||
|
|
"id": "536jWwBWg1Ou",
|
||
|
|
"outputId": "c589e021-e14e-4848-d8b5-2302c00d4ef7"
|
||
|
|
},
|
||
|
|
"outputs": [
|
||
|
|
{
|
||
|
|
"name": "stdout",
|
||
|
|
"output_type": "stream",
|
||
|
|
"text": [
|
||
|
|
"CPU times: user 213 ms, sys: 208 ms, total: 421 ms\n",
|
||
|
|
"Wall time: 597 ms\n"
|
||
|
|
]
|
||
|
|
},
|
||
|
|
{
|
||
|
|
"data": {
|
||
|
|
"text/html": [
|
||
|
|
"<style>#sk-container-id-3 {\n",
|
||
|
|
" /* Definition of color scheme common for light and dark mode */\n",
|
||
|
|
" --sklearn-color-text: #000;\n",
|
||
|
|
" --sklearn-color-text-muted: #666;\n",
|
||
|
|
" --sklearn-color-line: gray;\n",
|
||
|
|
" /* Definition of color scheme for unfitted estimators */\n",
|
||
|
|
" --sklearn-color-unfitted-level-0: #fff5e6;\n",
|
||
|
|
" --sklearn-color-unfitted-level-1: #f6e4d2;\n",
|
||
|
|
" --sklearn-color-unfitted-level-2: #ffe0b3;\n",
|
||
|
|
" --sklearn-color-unfitted-level-3: chocolate;\n",
|
||
|
|
" /* Definition of color scheme for fitted estimators */\n",
|
||
|
|
" --sklearn-color-fitted-level-0: #f0f8ff;\n",
|
||
|
|
" --sklearn-color-fitted-level-1: #d4ebff;\n",
|
||
|
|
" --sklearn-color-fitted-level-2: #b3dbfd;\n",
|
||
|
|
" --sklearn-color-fitted-level-3: cornflowerblue;\n",
|
||
|
|
"\n",
|
||
|
|
" /* Specific color for light theme */\n",
|
||
|
|
" --sklearn-color-text-on-default-background: var(--sg-text-color, var(--theme-code-foreground, var(--jp-content-font-color1, black)));\n",
|
||
|
|
" --sklearn-color-background: var(--sg-background-color, var(--theme-background, var(--jp-layout-color0, white)));\n",
|
||
|
|
" --sklearn-color-border-box: var(--sg-text-color, var(--theme-code-foreground, var(--jp-content-font-color1, black)));\n",
|
||
|
|
" --sklearn-color-icon: #696969;\n",
|
||
|
|
"\n",
|
||
|
|
" @media (prefers-color-scheme: dark) {\n",
|
||
|
|
" /* Redefinition of color scheme for dark theme */\n",
|
||
|
|
" --sklearn-color-text-on-default-background: var(--sg-text-color, var(--theme-code-foreground, var(--jp-content-font-color1, white)));\n",
|
||
|
|
" --sklearn-color-background: var(--sg-background-color, var(--theme-background, var(--jp-layout-color0, #111)));\n",
|
||
|
|
" --sklearn-color-border-box: var(--sg-text-color, var(--theme-code-foreground, var(--jp-content-font-color1, white)));\n",
|
||
|
|
" --sklearn-color-icon: #878787;\n",
|
||
|
|
" }\n",
|
||
|
|
"}\n",
|
||
|
|
"\n",
|
||
|
|
"#sk-container-id-3 {\n",
|
||
|
|
" color: var(--sklearn-color-text);\n",
|
||
|
|
"}\n",
|
||
|
|
"\n",
|
||
|
|
"#sk-container-id-3 pre {\n",
|
||
|
|
" padding: 0;\n",
|
||
|
|
"}\n",
|
||
|
|
"\n",
|
||
|
|
"#sk-container-id-3 input.sk-hidden--visually {\n",
|
||
|
|
" border: 0;\n",
|
||
|
|
" clip: rect(1px 1px 1px 1px);\n",
|
||
|
|
" clip: rect(1px, 1px, 1px, 1px);\n",
|
||
|
|
" height: 1px;\n",
|
||
|
|
" margin: -1px;\n",
|
||
|
|
" overflow: hidden;\n",
|
||
|
|
" padding: 0;\n",
|
||
|
|
" position: absolute;\n",
|
||
|
|
" width: 1px;\n",
|
||
|
|
"}\n",
|
||
|
|
"\n",
|
||
|
|
"#sk-container-id-3 div.sk-dashed-wrapped {\n",
|
||
|
|
" border: 1px dashed var(--sklearn-color-line);\n",
|
||
|
|
" margin: 0 0.4em 0.5em 0.4em;\n",
|
||
|
|
" box-sizing: border-box;\n",
|
||
|
|
" padding-bottom: 0.4em;\n",
|
||
|
|
" background-color: var(--sklearn-color-background);\n",
|
||
|
|
"}\n",
|
||
|
|
"\n",
|
||
|
|
"#sk-container-id-3 div.sk-container {\n",
|
||
|
|
" /* jupyter's `normalize.less` sets `[hidden] { display: none; }`\n",
|
||
|
|
" but bootstrap.min.css set `[hidden] { display: none !important; }`\n",
|
||
|
|
" so we also need the `!important` here to be able to override the\n",
|
||
|
|
" default hidden behavior on the sphinx rendered scikit-learn.org.\n",
|
||
|
|
" See: https://github.com/scikit-learn/scikit-learn/issues/21755 */\n",
|
||
|
|
" display: inline-block !important;\n",
|
||
|
|
" position: relative;\n",
|
||
|
|
"}\n",
|
||
|
|
"\n",
|
||
|
|
"#sk-container-id-3 div.sk-text-repr-fallback {\n",
|
||
|
|
" display: none;\n",
|
||
|
|
"}\n",
|
||
|
|
"\n",
|
||
|
|
"div.sk-parallel-item,\n",
|
||
|
|
"div.sk-serial,\n",
|
||
|
|
"div.sk-item {\n",
|
||
|
|
" /* draw centered vertical line to link estimators */\n",
|
||
|
|
" background-image: linear-gradient(var(--sklearn-color-text-on-default-background), var(--sklearn-color-text-on-default-background));\n",
|
||
|
|
" background-size: 2px 100%;\n",
|
||
|
|
" background-repeat: no-repeat;\n",
|
||
|
|
" background-position: center center;\n",
|
||
|
|
"}\n",
|
||
|
|
"\n",
|
||
|
|
"/* Parallel-specific style estimator block */\n",
|
||
|
|
"\n",
|
||
|
|
"#sk-container-id-3 div.sk-parallel-item::after {\n",
|
||
|
|
" content: \"\";\n",
|
||
|
|
" width: 100%;\n",
|
||
|
|
" border-bottom: 2px solid var(--sklearn-color-text-on-default-background);\n",
|
||
|
|
" flex-grow: 1;\n",
|
||
|
|
"}\n",
|
||
|
|
"\n",
|
||
|
|
"#sk-container-id-3 div.sk-parallel {\n",
|
||
|
|
" display: flex;\n",
|
||
|
|
" align-items: stretch;\n",
|
||
|
|
" justify-content: center;\n",
|
||
|
|
" background-color: var(--sklearn-color-background);\n",
|
||
|
|
" position: relative;\n",
|
||
|
|
"}\n",
|
||
|
|
"\n",
|
||
|
|
"#sk-container-id-3 div.sk-parallel-item {\n",
|
||
|
|
" display: flex;\n",
|
||
|
|
" flex-direction: column;\n",
|
||
|
|
"}\n",
|
||
|
|
"\n",
|
||
|
|
"#sk-container-id-3 div.sk-parallel-item:first-child::after {\n",
|
||
|
|
" align-self: flex-end;\n",
|
||
|
|
" width: 50%;\n",
|
||
|
|
"}\n",
|
||
|
|
"\n",
|
||
|
|
"#sk-container-id-3 div.sk-parallel-item:last-child::after {\n",
|
||
|
|
" align-self: flex-start;\n",
|
||
|
|
" width: 50%;\n",
|
||
|
|
"}\n",
|
||
|
|
"\n",
|
||
|
|
"#sk-container-id-3 div.sk-parallel-item:only-child::after {\n",
|
||
|
|
" width: 0;\n",
|
||
|
|
"}\n",
|
||
|
|
"\n",
|
||
|
|
"/* Serial-specific style estimator block */\n",
|
||
|
|
"\n",
|
||
|
|
"#sk-container-id-3 div.sk-serial {\n",
|
||
|
|
" display: flex;\n",
|
||
|
|
" flex-direction: column;\n",
|
||
|
|
" align-items: center;\n",
|
||
|
|
" background-color: var(--sklearn-color-background);\n",
|
||
|
|
" padding-right: 1em;\n",
|
||
|
|
" padding-left: 1em;\n",
|
||
|
|
"}\n",
|
||
|
|
"\n",
|
||
|
|
"\n",
|
||
|
|
"/* Toggleable style: style used for estimator/Pipeline/ColumnTransformer box that is\n",
|
||
|
|
"clickable and can be expanded/collapsed.\n",
|
||
|
|
"- Pipeline and ColumnTransformer use this feature and define the default style\n",
|
||
|
|
"- Estimators will overwrite some part of the style using the `sk-estimator` class\n",
|
||
|
|
"*/\n",
|
||
|
|
"\n",
|
||
|
|
"/* Pipeline and ColumnTransformer style (default) */\n",
|
||
|
|
"\n",
|
||
|
|
"#sk-container-id-3 div.sk-toggleable {\n",
|
||
|
|
" /* Default theme specific background. It is overwritten whether we have a\n",
|
||
|
|
" specific estimator or a Pipeline/ColumnTransformer */\n",
|
||
|
|
" background-color: var(--sklearn-color-background);\n",
|
||
|
|
"}\n",
|
||
|
|
"\n",
|
||
|
|
"/* Toggleable label */\n",
|
||
|
|
"#sk-container-id-3 label.sk-toggleable__label {\n",
|
||
|
|
" cursor: pointer;\n",
|
||
|
|
" display: flex;\n",
|
||
|
|
" width: 100%;\n",
|
||
|
|
" margin-bottom: 0;\n",
|
||
|
|
" padding: 0.5em;\n",
|
||
|
|
" box-sizing: border-box;\n",
|
||
|
|
" text-align: center;\n",
|
||
|
|
" align-items: start;\n",
|
||
|
|
" justify-content: space-between;\n",
|
||
|
|
" gap: 0.5em;\n",
|
||
|
|
"}\n",
|
||
|
|
"\n",
|
||
|
|
"#sk-container-id-3 label.sk-toggleable__label .caption {\n",
|
||
|
|
" font-size: 0.6rem;\n",
|
||
|
|
" font-weight: lighter;\n",
|
||
|
|
" color: var(--sklearn-color-text-muted);\n",
|
||
|
|
"}\n",
|
||
|
|
"\n",
|
||
|
|
"#sk-container-id-3 label.sk-toggleable__label-arrow:before {\n",
|
||
|
|
" /* Arrow on the left of the label */\n",
|
||
|
|
" content: \"▸\";\n",
|
||
|
|
" float: left;\n",
|
||
|
|
" margin-right: 0.25em;\n",
|
||
|
|
" color: var(--sklearn-color-icon);\n",
|
||
|
|
"}\n",
|
||
|
|
"\n",
|
||
|
|
"#sk-container-id-3 label.sk-toggleable__label-arrow:hover:before {\n",
|
||
|
|
" color: var(--sklearn-color-text);\n",
|
||
|
|
"}\n",
|
||
|
|
"\n",
|
||
|
|
"/* Toggleable content - dropdown */\n",
|
||
|
|
"\n",
|
||
|
|
"#sk-container-id-3 div.sk-toggleable__content {\n",
|
||
|
|
" display: none;\n",
|
||
|
|
" text-align: left;\n",
|
||
|
|
" /* unfitted */\n",
|
||
|
|
" background-color: var(--sklearn-color-unfitted-level-0);\n",
|
||
|
|
"}\n",
|
||
|
|
"\n",
|
||
|
|
"#sk-container-id-3 div.sk-toggleable__content.fitted {\n",
|
||
|
|
" /* fitted */\n",
|
||
|
|
" background-color: var(--sklearn-color-fitted-level-0);\n",
|
||
|
|
"}\n",
|
||
|
|
"\n",
|
||
|
|
"#sk-container-id-3 div.sk-toggleable__content pre {\n",
|
||
|
|
" margin: 0.2em;\n",
|
||
|
|
" border-radius: 0.25em;\n",
|
||
|
|
" color: var(--sklearn-color-text);\n",
|
||
|
|
" /* unfitted */\n",
|
||
|
|
" background-color: var(--sklearn-color-unfitted-level-0);\n",
|
||
|
|
"}\n",
|
||
|
|
"\n",
|
||
|
|
"#sk-container-id-3 div.sk-toggleable__content.fitted pre {\n",
|
||
|
|
" /* unfitted */\n",
|
||
|
|
" background-color: var(--sklearn-color-fitted-level-0);\n",
|
||
|
|
"}\n",
|
||
|
|
"\n",
|
||
|
|
"#sk-container-id-3 input.sk-toggleable__control:checked~div.sk-toggleable__content {\n",
|
||
|
|
" /* Expand drop-down */\n",
|
||
|
|
" display: block;\n",
|
||
|
|
" width: 100%;\n",
|
||
|
|
" overflow: visible;\n",
|
||
|
|
"}\n",
|
||
|
|
"\n",
|
||
|
|
"#sk-container-id-3 input.sk-toggleable__control:checked~label.sk-toggleable__label-arrow:before {\n",
|
||
|
|
" content: \"▾\";\n",
|
||
|
|
"}\n",
|
||
|
|
"\n",
|
||
|
|
"/* Pipeline/ColumnTransformer-specific style */\n",
|
||
|
|
"\n",
|
||
|
|
"#sk-container-id-3 div.sk-label input.sk-toggleable__control:checked~label.sk-toggleable__label {\n",
|
||
|
|
" color: var(--sklearn-color-text);\n",
|
||
|
|
" background-color: var(--sklearn-color-unfitted-level-2);\n",
|
||
|
|
"}\n",
|
||
|
|
"\n",
|
||
|
|
"#sk-container-id-3 div.sk-label.fitted input.sk-toggleable__control:checked~label.sk-toggleable__label {\n",
|
||
|
|
" background-color: var(--sklearn-color-fitted-level-2);\n",
|
||
|
|
"}\n",
|
||
|
|
"\n",
|
||
|
|
"/* Estimator-specific style */\n",
|
||
|
|
"\n",
|
||
|
|
"/* Colorize estimator box */\n",
|
||
|
|
"#sk-container-id-3 div.sk-estimator input.sk-toggleable__control:checked~label.sk-toggleable__label {\n",
|
||
|
|
" /* unfitted */\n",
|
||
|
|
" background-color: var(--sklearn-color-unfitted-level-2);\n",
|
||
|
|
"}\n",
|
||
|
|
"\n",
|
||
|
|
"#sk-container-id-3 div.sk-estimator.fitted input.sk-toggleable__control:checked~label.sk-toggleable__label {\n",
|
||
|
|
" /* fitted */\n",
|
||
|
|
" background-color: var(--sklearn-color-fitted-level-2);\n",
|
||
|
|
"}\n",
|
||
|
|
"\n",
|
||
|
|
"#sk-container-id-3 div.sk-label label.sk-toggleable__label,\n",
|
||
|
|
"#sk-container-id-3 div.sk-label label {\n",
|
||
|
|
" /* The background is the default theme color */\n",
|
||
|
|
" color: var(--sklearn-color-text-on-default-background);\n",
|
||
|
|
"}\n",
|
||
|
|
"\n",
|
||
|
|
"/* On hover, darken the color of the background */\n",
|
||
|
|
"#sk-container-id-3 div.sk-label:hover label.sk-toggleable__label {\n",
|
||
|
|
" color: var(--sklearn-color-text);\n",
|
||
|
|
" background-color: var(--sklearn-color-unfitted-level-2);\n",
|
||
|
|
"}\n",
|
||
|
|
"\n",
|
||
|
|
"/* Label box, darken color on hover, fitted */\n",
|
||
|
|
"#sk-container-id-3 div.sk-label.fitted:hover label.sk-toggleable__label.fitted {\n",
|
||
|
|
" color: var(--sklearn-color-text);\n",
|
||
|
|
" background-color: var(--sklearn-color-fitted-level-2);\n",
|
||
|
|
"}\n",
|
||
|
|
"\n",
|
||
|
|
"/* Estimator label */\n",
|
||
|
|
"\n",
|
||
|
|
"#sk-container-id-3 div.sk-label label {\n",
|
||
|
|
" font-family: monospace;\n",
|
||
|
|
" font-weight: bold;\n",
|
||
|
|
" display: inline-block;\n",
|
||
|
|
" line-height: 1.2em;\n",
|
||
|
|
"}\n",
|
||
|
|
"\n",
|
||
|
|
"#sk-container-id-3 div.sk-label-container {\n",
|
||
|
|
" text-align: center;\n",
|
||
|
|
"}\n",
|
||
|
|
"\n",
|
||
|
|
"/* Estimator-specific */\n",
|
||
|
|
"#sk-container-id-3 div.sk-estimator {\n",
|
||
|
|
" font-family: monospace;\n",
|
||
|
|
" border: 1px dotted var(--sklearn-color-border-box);\n",
|
||
|
|
" border-radius: 0.25em;\n",
|
||
|
|
" box-sizing: border-box;\n",
|
||
|
|
" margin-bottom: 0.5em;\n",
|
||
|
|
" /* unfitted */\n",
|
||
|
|
" background-color: var(--sklearn-color-unfitted-level-0);\n",
|
||
|
|
"}\n",
|
||
|
|
"\n",
|
||
|
|
"#sk-container-id-3 div.sk-estimator.fitted {\n",
|
||
|
|
" /* fitted */\n",
|
||
|
|
" background-color: var(--sklearn-color-fitted-level-0);\n",
|
||
|
|
"}\n",
|
||
|
|
"\n",
|
||
|
|
"/* on hover */\n",
|
||
|
|
"#sk-container-id-3 div.sk-estimator:hover {\n",
|
||
|
|
" /* unfitted */\n",
|
||
|
|
" background-color: var(--sklearn-color-unfitted-level-2);\n",
|
||
|
|
"}\n",
|
||
|
|
"\n",
|
||
|
|
"#sk-container-id-3 div.sk-estimator.fitted:hover {\n",
|
||
|
|
" /* fitted */\n",
|
||
|
|
" background-color: var(--sklearn-color-fitted-level-2);\n",
|
||
|
|
"}\n",
|
||
|
|
"\n",
|
||
|
|
"/* Specification for estimator info (e.g. \"i\" and \"?\") */\n",
|
||
|
|
"\n",
|
||
|
|
"/* Common style for \"i\" and \"?\" */\n",
|
||
|
|
"\n",
|
||
|
|
".sk-estimator-doc-link,\n",
|
||
|
|
"a:link.sk-estimator-doc-link,\n",
|
||
|
|
"a:visited.sk-estimator-doc-link {\n",
|
||
|
|
" float: right;\n",
|
||
|
|
" font-size: smaller;\n",
|
||
|
|
" line-height: 1em;\n",
|
||
|
|
" font-family: monospace;\n",
|
||
|
|
" background-color: var(--sklearn-color-background);\n",
|
||
|
|
" border-radius: 1em;\n",
|
||
|
|
" height: 1em;\n",
|
||
|
|
" width: 1em;\n",
|
||
|
|
" text-decoration: none !important;\n",
|
||
|
|
" margin-left: 0.5em;\n",
|
||
|
|
" text-align: center;\n",
|
||
|
|
" /* unfitted */\n",
|
||
|
|
" border: var(--sklearn-color-unfitted-level-1) 1pt solid;\n",
|
||
|
|
" color: var(--sklearn-color-unfitted-level-1);\n",
|
||
|
|
"}\n",
|
||
|
|
"\n",
|
||
|
|
".sk-estimator-doc-link.fitted,\n",
|
||
|
|
"a:link.sk-estimator-doc-link.fitted,\n",
|
||
|
|
"a:visited.sk-estimator-doc-link.fitted {\n",
|
||
|
|
" /* fitted */\n",
|
||
|
|
" border: var(--sklearn-color-fitted-level-1) 1pt solid;\n",
|
||
|
|
" color: var(--sklearn-color-fitted-level-1);\n",
|
||
|
|
"}\n",
|
||
|
|
"\n",
|
||
|
|
"/* On hover */\n",
|
||
|
|
"div.sk-estimator:hover .sk-estimator-doc-link:hover,\n",
|
||
|
|
".sk-estimator-doc-link:hover,\n",
|
||
|
|
"div.sk-label-container:hover .sk-estimator-doc-link:hover,\n",
|
||
|
|
".sk-estimator-doc-link:hover {\n",
|
||
|
|
" /* unfitted */\n",
|
||
|
|
" background-color: var(--sklearn-color-unfitted-level-3);\n",
|
||
|
|
" color: var(--sklearn-color-background);\n",
|
||
|
|
" text-decoration: none;\n",
|
||
|
|
"}\n",
|
||
|
|
"\n",
|
||
|
|
"div.sk-estimator.fitted:hover .sk-estimator-doc-link.fitted:hover,\n",
|
||
|
|
".sk-estimator-doc-link.fitted:hover,\n",
|
||
|
|
"div.sk-label-container:hover .sk-estimator-doc-link.fitted:hover,\n",
|
||
|
|
".sk-estimator-doc-link.fitted:hover {\n",
|
||
|
|
" /* fitted */\n",
|
||
|
|
" background-color: var(--sklearn-color-fitted-level-3);\n",
|
||
|
|
" color: var(--sklearn-color-background);\n",
|
||
|
|
" text-decoration: none;\n",
|
||
|
|
"}\n",
|
||
|
|
"\n",
|
||
|
|
"/* Span, style for the box shown on hovering the info icon */\n",
|
||
|
|
".sk-estimator-doc-link span {\n",
|
||
|
|
" display: none;\n",
|
||
|
|
" z-index: 9999;\n",
|
||
|
|
" position: relative;\n",
|
||
|
|
" font-weight: normal;\n",
|
||
|
|
" right: .2ex;\n",
|
||
|
|
" padding: .5ex;\n",
|
||
|
|
" margin: .5ex;\n",
|
||
|
|
" width: min-content;\n",
|
||
|
|
" min-width: 20ex;\n",
|
||
|
|
" max-width: 50ex;\n",
|
||
|
|
" color: var(--sklearn-color-text);\n",
|
||
|
|
" box-shadow: 2pt 2pt 4pt #999;\n",
|
||
|
|
" /* unfitted */\n",
|
||
|
|
" background: var(--sklearn-color-unfitted-level-0);\n",
|
||
|
|
" border: .5pt solid var(--sklearn-color-unfitted-level-3);\n",
|
||
|
|
"}\n",
|
||
|
|
"\n",
|
||
|
|
".sk-estimator-doc-link.fitted span {\n",
|
||
|
|
" /* fitted */\n",
|
||
|
|
" background: var(--sklearn-color-fitted-level-0);\n",
|
||
|
|
" border: var(--sklearn-color-fitted-level-3);\n",
|
||
|
|
"}\n",
|
||
|
|
"\n",
|
||
|
|
".sk-estimator-doc-link:hover span {\n",
|
||
|
|
" display: block;\n",
|
||
|
|
"}\n",
|
||
|
|
"\n",
|
||
|
|
"/* \"?\"-specific style due to the `<a>` HTML tag */\n",
|
||
|
|
"\n",
|
||
|
|
"#sk-container-id-3 a.estimator_doc_link {\n",
|
||
|
|
" float: right;\n",
|
||
|
|
" font-size: 1rem;\n",
|
||
|
|
" line-height: 1em;\n",
|
||
|
|
" font-family: monospace;\n",
|
||
|
|
" background-color: var(--sklearn-color-background);\n",
|
||
|
|
" border-radius: 1rem;\n",
|
||
|
|
" height: 1rem;\n",
|
||
|
|
" width: 1rem;\n",
|
||
|
|
" text-decoration: none;\n",
|
||
|
|
" /* unfitted */\n",
|
||
|
|
" color: var(--sklearn-color-unfitted-level-1);\n",
|
||
|
|
" border: var(--sklearn-color-unfitted-level-1) 1pt solid;\n",
|
||
|
|
"}\n",
|
||
|
|
"\n",
|
||
|
|
"#sk-container-id-3 a.estimator_doc_link.fitted {\n",
|
||
|
|
" /* fitted */\n",
|
||
|
|
" border: var(--sklearn-color-fitted-level-1) 1pt solid;\n",
|
||
|
|
" color: var(--sklearn-color-fitted-level-1);\n",
|
||
|
|
"}\n",
|
||
|
|
"\n",
|
||
|
|
"/* On hover */\n",
|
||
|
|
"#sk-container-id-3 a.estimator_doc_link:hover {\n",
|
||
|
|
" /* unfitted */\n",
|
||
|
|
" background-color: var(--sklearn-color-unfitted-level-3);\n",
|
||
|
|
" color: var(--sklearn-color-background);\n",
|
||
|
|
" text-decoration: none;\n",
|
||
|
|
"}\n",
|
||
|
|
"\n",
|
||
|
|
"#sk-container-id-3 a.estimator_doc_link.fitted:hover {\n",
|
||
|
|
" /* fitted */\n",
|
||
|
|
" background-color: var(--sklearn-color-fitted-level-3);\n",
|
||
|
|
"}\n",
|
||
|
|
"\n",
|
||
|
|
".estimator-table summary {\n",
|
||
|
|
" padding: .5rem;\n",
|
||
|
|
" font-family: monospace;\n",
|
||
|
|
" cursor: pointer;\n",
|
||
|
|
"}\n",
|
||
|
|
"\n",
|
||
|
|
".estimator-table details[open] {\n",
|
||
|
|
" padding-left: 0.1rem;\n",
|
||
|
|
" padding-right: 0.1rem;\n",
|
||
|
|
" padding-bottom: 0.3rem;\n",
|
||
|
|
"}\n",
|
||
|
|
"\n",
|
||
|
|
".estimator-table .parameters-table {\n",
|
||
|
|
" margin-left: auto !important;\n",
|
||
|
|
" margin-right: auto !important;\n",
|
||
|
|
"}\n",
|
||
|
|
"\n",
|
||
|
|
".estimator-table .parameters-table tr:nth-child(odd) {\n",
|
||
|
|
" background-color: #fff;\n",
|
||
|
|
"}\n",
|
||
|
|
"\n",
|
||
|
|
".estimator-table .parameters-table tr:nth-child(even) {\n",
|
||
|
|
" background-color: #f6f6f6;\n",
|
||
|
|
"}\n",
|
||
|
|
"\n",
|
||
|
|
".estimator-table .parameters-table tr:hover {\n",
|
||
|
|
" background-color: #e0e0e0;\n",
|
||
|
|
"}\n",
|
||
|
|
"\n",
|
||
|
|
".estimator-table table td {\n",
|
||
|
|
" border: 1px solid rgba(106, 105, 104, 0.232);\n",
|
||
|
|
"}\n",
|
||
|
|
"\n",
|
||
|
|
".user-set td {\n",
|
||
|
|
" color:rgb(255, 94, 0);\n",
|
||
|
|
" text-align: left;\n",
|
||
|
|
"}\n",
|
||
|
|
"\n",
|
||
|
|
".user-set td.value pre {\n",
|
||
|
|
" color:rgb(255, 94, 0) !important;\n",
|
||
|
|
" background-color: transparent !important;\n",
|
||
|
|
"}\n",
|
||
|
|
"\n",
|
||
|
|
".default td {\n",
|
||
|
|
" color: black;\n",
|
||
|
|
" text-align: left;\n",
|
||
|
|
"}\n",
|
||
|
|
"\n",
|
||
|
|
".user-set td i,\n",
|
||
|
|
".default td i {\n",
|
||
|
|
" color: black;\n",
|
||
|
|
"}\n",
|
||
|
|
"\n",
|
||
|
|
".copy-paste-icon {\n",
|
||
|
|
" background-image: url(data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHZpZXdCb3g9IjAgMCA0NDggNTEyIj48IS0tIUZvbnQgQXdlc29tZSBGcmVlIDYuNy4yIGJ5IEBmb250YXdlc29tZSAtIGh0dHBzOi8vZm9udGF3ZXNvbWUuY29tIExpY2Vuc2UgLSBodHRwczovL2ZvbnRhd2Vzb21lLmNvbS9saWNlbnNlL2ZyZWUgQ29weXJpZ2h0IDIwMjUgRm9udGljb25zLCBJbmMuLS0+PHBhdGggZD0iTTIwOCAwTDMzMi4xIDBjMTIuNyAwIDI0LjkgNS4xIDMzLjkgMTQuMWw2Ny45IDY3LjljOSA5IDE0LjEgMjEuMiAxNC4xIDMzLjlMNDQ4IDMzNmMwIDI2LjUtMjEuNSA0OC00OCA0OGwtMTkyIDBjLTI2LjUgMC00OC0yMS41LTQ4LTQ4bDAtMjg4YzAtMjYuNSAyMS41LTQ4IDQ4LTQ4ek00OCAxMjhsODAgMCAwIDY0LTY0IDAgMCAyNTYgMTkyIDAgMC0zMiA2NCAwIDAgNDhjMCAyNi41LTIxLjUgNDgtNDggNDhMNDggNTEyYy0yNi41IDAtNDgtMjEuNS00OC00OEwwIDE3NmMwLTI2LjUgMjEuNS00OCA0OC00OHoiLz48L3N2Zz4=);\n",
|
||
|
|
" background-repeat: no-repeat;\n",
|
||
|
|
" background-size: 14px 14px;\n",
|
||
|
|
" background-position: 0;\n",
|
||
|
|
" display: inline-block;\n",
|
||
|
|
" width: 14px;\n",
|
||
|
|
" height: 14px;\n",
|
||
|
|
" cursor: pointer;\n",
|
||
|
|
"}\n",
|
||
|
|
"</style><body><div id=\"sk-container-id-3\" class=\"sk-top-container\"><div class=\"sk-text-repr-fallback\"><pre>HDBSCAN()</pre><b>In a Jupyter environment, please rerun this cell to show the HTML representation or trust the notebook. <br />On GitHub, the HTML representation is unable to render, please try loading this page with nbviewer.org.</b></div><div class=\"sk-container\" hidden><div class=\"sk-item\"><div class=\"sk-estimator fitted sk-toggleable\"><input class=\"sk-toggleable__control sk-hidden--visually\" id=\"sk-estimator-id-3\" type=\"checkbox\" checked><label for=\"sk-estimator-id-3\" class=\"sk-toggleable__label fitted sk-toggleable__label-arrow\"><div><div>HDBSCAN</div></div><div><span class=\"sk-estimator-doc-link fitted\">i<span>Fitted</span></span></div></label><div class=\"sk-toggleable__content fitted\" data-param-prefix=\"\">\n",
|
||
|
|
" <div class=\"estimator-table\">\n",
|
||
|
|
" <details>\n",
|
||
|
|
" <summary>Parameters</summary>\n",
|
||
|
|
" <table class=\"parameters-table\">\n",
|
||
|
|
" <tbody>\n",
|
||
|
|
" \n",
|
||
|
|
" <tr class=\"default\">\n",
|
||
|
|
" <td><i class=\"copy-paste-icon\"\n",
|
||
|
|
" onclick=\"copyToClipboard('min_cluster_size',\n",
|
||
|
|
" this.parentElement.nextElementSibling)\"\n",
|
||
|
|
" ></i></td>\n",
|
||
|
|
" <td class=\"param\">min_cluster_size </td>\n",
|
||
|
|
" <td class=\"value\">5</td>\n",
|
||
|
|
" </tr>\n",
|
||
|
|
" \n",
|
||
|
|
"\n",
|
||
|
|
" <tr class=\"default\">\n",
|
||
|
|
" <td><i class=\"copy-paste-icon\"\n",
|
||
|
|
" onclick=\"copyToClipboard('min_samples',\n",
|
||
|
|
" this.parentElement.nextElementSibling)\"\n",
|
||
|
|
" ></i></td>\n",
|
||
|
|
" <td class=\"param\">min_samples </td>\n",
|
||
|
|
" <td class=\"value\">None</td>\n",
|
||
|
|
" </tr>\n",
|
||
|
|
" \n",
|
||
|
|
"\n",
|
||
|
|
" <tr class=\"default\">\n",
|
||
|
|
" <td><i class=\"copy-paste-icon\"\n",
|
||
|
|
" onclick=\"copyToClipboard('cluster_selection_epsilon',\n",
|
||
|
|
" this.parentElement.nextElementSibling)\"\n",
|
||
|
|
" ></i></td>\n",
|
||
|
|
" <td class=\"param\">cluster_selection_epsilon </td>\n",
|
||
|
|
" <td class=\"value\">0.0</td>\n",
|
||
|
|
" </tr>\n",
|
||
|
|
" \n",
|
||
|
|
"\n",
|
||
|
|
" <tr class=\"default\">\n",
|
||
|
|
" <td><i class=\"copy-paste-icon\"\n",
|
||
|
|
" onclick=\"copyToClipboard('max_cluster_size',\n",
|
||
|
|
" this.parentElement.nextElementSibling)\"\n",
|
||
|
|
" ></i></td>\n",
|
||
|
|
" <td class=\"param\">max_cluster_size </td>\n",
|
||
|
|
" <td class=\"value\">0</td>\n",
|
||
|
|
" </tr>\n",
|
||
|
|
" \n",
|
||
|
|
"\n",
|
||
|
|
" <tr class=\"default\">\n",
|
||
|
|
" <td><i class=\"copy-paste-icon\"\n",
|
||
|
|
" onclick=\"copyToClipboard('metric',\n",
|
||
|
|
" this.parentElement.nextElementSibling)\"\n",
|
||
|
|
" ></i></td>\n",
|
||
|
|
" <td class=\"param\">metric </td>\n",
|
||
|
|
" <td class=\"value\">'euclidean'</td>\n",
|
||
|
|
" </tr>\n",
|
||
|
|
" \n",
|
||
|
|
"\n",
|
||
|
|
" <tr class=\"default\">\n",
|
||
|
|
" <td><i class=\"copy-paste-icon\"\n",
|
||
|
|
" onclick=\"copyToClipboard('alpha',\n",
|
||
|
|
" this.parentElement.nextElementSibling)\"\n",
|
||
|
|
" ></i></td>\n",
|
||
|
|
" <td class=\"param\">alpha </td>\n",
|
||
|
|
" <td class=\"value\">1.0</td>\n",
|
||
|
|
" </tr>\n",
|
||
|
|
" \n",
|
||
|
|
"\n",
|
||
|
|
" <tr class=\"default\">\n",
|
||
|
|
" <td><i class=\"copy-paste-icon\"\n",
|
||
|
|
" onclick=\"copyToClipboard('p',\n",
|
||
|
|
" this.parentElement.nextElementSibling)\"\n",
|
||
|
|
" ></i></td>\n",
|
||
|
|
" <td class=\"param\">p </td>\n",
|
||
|
|
" <td class=\"value\">None</td>\n",
|
||
|
|
" </tr>\n",
|
||
|
|
" \n",
|
||
|
|
"\n",
|
||
|
|
" <tr class=\"default\">\n",
|
||
|
|
" <td><i class=\"copy-paste-icon\"\n",
|
||
|
|
" onclick=\"copyToClipboard('algorithm',\n",
|
||
|
|
" this.parentElement.nextElementSibling)\"\n",
|
||
|
|
" ></i></td>\n",
|
||
|
|
" <td class=\"param\">algorithm </td>\n",
|
||
|
|
" <td class=\"value\">'best'</td>\n",
|
||
|
|
" </tr>\n",
|
||
|
|
" \n",
|
||
|
|
"\n",
|
||
|
|
" <tr class=\"default\">\n",
|
||
|
|
" <td><i class=\"copy-paste-icon\"\n",
|
||
|
|
" onclick=\"copyToClipboard('leaf_size',\n",
|
||
|
|
" this.parentElement.nextElementSibling)\"\n",
|
||
|
|
" ></i></td>\n",
|
||
|
|
" <td class=\"param\">leaf_size </td>\n",
|
||
|
|
" <td class=\"value\">40</td>\n",
|
||
|
|
" </tr>\n",
|
||
|
|
" \n",
|
||
|
|
"\n",
|
||
|
|
" <tr class=\"user-set\">\n",
|
||
|
|
" <td><i class=\"copy-paste-icon\"\n",
|
||
|
|
" onclick=\"copyToClipboard('memory',\n",
|
||
|
|
" this.parentElement.nextElementSibling)\"\n",
|
||
|
|
" ></i></td>\n",
|
||
|
|
" <td class=\"param\">memory </td>\n",
|
||
|
|
" <td class=\"value\">Memory(location=None)</td>\n",
|
||
|
|
" </tr>\n",
|
||
|
|
" \n",
|
||
|
|
"\n",
|
||
|
|
" <tr class=\"default\">\n",
|
||
|
|
" <td><i class=\"copy-paste-icon\"\n",
|
||
|
|
" onclick=\"copyToClipboard('approx_min_span_tree',\n",
|
||
|
|
" this.parentElement.nextElementSibling)\"\n",
|
||
|
|
" ></i></td>\n",
|
||
|
|
" <td class=\"param\">approx_min_span_tree </td>\n",
|
||
|
|
" <td class=\"value\">True</td>\n",
|
||
|
|
" </tr>\n",
|
||
|
|
" \n",
|
||
|
|
"\n",
|
||
|
|
" <tr class=\"default\">\n",
|
||
|
|
" <td><i class=\"copy-paste-icon\"\n",
|
||
|
|
" onclick=\"copyToClipboard('gen_min_span_tree',\n",
|
||
|
|
" this.parentElement.nextElementSibling)\"\n",
|
||
|
|
" ></i></td>\n",
|
||
|
|
" <td class=\"param\">gen_min_span_tree </td>\n",
|
||
|
|
" <td class=\"value\">False</td>\n",
|
||
|
|
" </tr>\n",
|
||
|
|
" \n",
|
||
|
|
"\n",
|
||
|
|
" <tr class=\"default\">\n",
|
||
|
|
" <td><i class=\"copy-paste-icon\"\n",
|
||
|
|
" onclick=\"copyToClipboard('core_dist_n_jobs',\n",
|
||
|
|
" this.parentElement.nextElementSibling)\"\n",
|
||
|
|
" ></i></td>\n",
|
||
|
|
" <td class=\"param\">core_dist_n_jobs </td>\n",
|
||
|
|
" <td class=\"value\">4</td>\n",
|
||
|
|
" </tr>\n",
|
||
|
|
" \n",
|
||
|
|
"\n",
|
||
|
|
" <tr class=\"default\">\n",
|
||
|
|
" <td><i class=\"copy-paste-icon\"\n",
|
||
|
|
" onclick=\"copyToClipboard('cluster_selection_method',\n",
|
||
|
|
" this.parentElement.nextElementSibling)\"\n",
|
||
|
|
" ></i></td>\n",
|
||
|
|
" <td class=\"param\">cluster_selection_method </td>\n",
|
||
|
|
" <td class=\"value\">'eom'</td>\n",
|
||
|
|
" </tr>\n",
|
||
|
|
" \n",
|
||
|
|
"\n",
|
||
|
|
" <tr class=\"default\">\n",
|
||
|
|
" <td><i class=\"copy-paste-icon\"\n",
|
||
|
|
" onclick=\"copyToClipboard('allow_single_cluster',\n",
|
||
|
|
" this.parentElement.nextElementSibling)\"\n",
|
||
|
|
" ></i></td>\n",
|
||
|
|
" <td class=\"param\">allow_single_cluster </td>\n",
|
||
|
|
" <td class=\"value\">False</td>\n",
|
||
|
|
" </tr>\n",
|
||
|
|
" \n",
|
||
|
|
"\n",
|
||
|
|
" <tr class=\"default\">\n",
|
||
|
|
" <td><i class=\"copy-paste-icon\"\n",
|
||
|
|
" onclick=\"copyToClipboard('prediction_data',\n",
|
||
|
|
" this.parentElement.nextElementSibling)\"\n",
|
||
|
|
" ></i></td>\n",
|
||
|
|
" <td class=\"param\">prediction_data </td>\n",
|
||
|
|
" <td class=\"value\">False</td>\n",
|
||
|
|
" </tr>\n",
|
||
|
|
" \n",
|
||
|
|
"\n",
|
||
|
|
" <tr class=\"default\">\n",
|
||
|
|
" <td><i class=\"copy-paste-icon\"\n",
|
||
|
|
" onclick=\"copyToClipboard('branch_detection_data',\n",
|
||
|
|
" this.parentElement.nextElementSibling)\"\n",
|
||
|
|
" ></i></td>\n",
|
||
|
|
" <td class=\"param\">branch_detection_data </td>\n",
|
||
|
|
" <td class=\"value\">False</td>\n",
|
||
|
|
" </tr>\n",
|
||
|
|
" \n",
|
||
|
|
"\n",
|
||
|
|
" <tr class=\"default\">\n",
|
||
|
|
" <td><i class=\"copy-paste-icon\"\n",
|
||
|
|
" onclick=\"copyToClipboard('match_reference_implementation',\n",
|
||
|
|
" this.parentElement.nextElementSibling)\"\n",
|
||
|
|
" ></i></td>\n",
|
||
|
|
" <td class=\"param\">match_reference_implementation </td>\n",
|
||
|
|
" <td class=\"value\">False</td>\n",
|
||
|
|
" </tr>\n",
|
||
|
|
" \n",
|
||
|
|
"\n",
|
||
|
|
" <tr class=\"default\">\n",
|
||
|
|
" <td><i class=\"copy-paste-icon\"\n",
|
||
|
|
" onclick=\"copyToClipboard('cluster_selection_epsilon_max',\n",
|
||
|
|
" this.parentElement.nextElementSibling)\"\n",
|
||
|
|
" ></i></td>\n",
|
||
|
|
" <td class=\"param\">cluster_selection_epsilon_max </td>\n",
|
||
|
|
" <td class=\"value\">inf</td>\n",
|
||
|
|
" </tr>\n",
|
||
|
|
" \n",
|
||
|
|
" </tbody>\n",
|
||
|
|
" </table>\n",
|
||
|
|
" </details>\n",
|
||
|
|
" </div>\n",
|
||
|
|
" </div></div></div></div></div><script>function copyToClipboard(text, element) {\n",
|
||
|
|
" // Get the parameter prefix from the closest toggleable content\n",
|
||
|
|
" const toggleableContent = element.closest('.sk-toggleable__content');\n",
|
||
|
|
" const paramPrefix = toggleableContent ? toggleableContent.dataset.paramPrefix : '';\n",
|
||
|
|
" const fullParamName = paramPrefix ? `${paramPrefix}${text}` : text;\n",
|
||
|
|
"\n",
|
||
|
|
" const originalStyle = element.style;\n",
|
||
|
|
" const computedStyle = window.getComputedStyle(element);\n",
|
||
|
|
" const originalWidth = computedStyle.width;\n",
|
||
|
|
" const originalHTML = element.innerHTML.replace('Copied!', '');\n",
|
||
|
|
"\n",
|
||
|
|
" navigator.clipboard.writeText(fullParamName)\n",
|
||
|
|
" .then(() => {\n",
|
||
|
|
" element.style.width = originalWidth;\n",
|
||
|
|
" element.style.color = 'green';\n",
|
||
|
|
" element.innerHTML = \"Copied!\";\n",
|
||
|
|
"\n",
|
||
|
|
" setTimeout(() => {\n",
|
||
|
|
" element.innerHTML = originalHTML;\n",
|
||
|
|
" element.style = originalStyle;\n",
|
||
|
|
" }, 2000);\n",
|
||
|
|
" })\n",
|
||
|
|
" .catch(err => {\n",
|
||
|
|
" console.error('Failed to copy:', err);\n",
|
||
|
|
" element.style.color = 'red';\n",
|
||
|
|
" element.innerHTML = \"Failed!\";\n",
|
||
|
|
" setTimeout(() => {\n",
|
||
|
|
" element.innerHTML = originalHTML;\n",
|
||
|
|
" element.style = originalStyle;\n",
|
||
|
|
" }, 2000);\n",
|
||
|
|
" });\n",
|
||
|
|
" return false;\n",
|
||
|
|
"}\n",
|
||
|
|
"\n",
|
||
|
|
"document.querySelectorAll('.fa-regular.fa-copy').forEach(function(element) {\n",
|
||
|
|
" const toggleableContent = element.closest('.sk-toggleable__content');\n",
|
||
|
|
" const paramPrefix = toggleableContent ? toggleableContent.dataset.paramPrefix : '';\n",
|
||
|
|
" const paramName = element.parentElement.nextElementSibling.textContent.trim();\n",
|
||
|
|
" const fullParamName = paramPrefix ? `${paramPrefix}${paramName}` : paramName;\n",
|
||
|
|
"\n",
|
||
|
|
" element.setAttribute('title', fullParamName);\n",
|
||
|
|
"});\n",
|
||
|
|
"</script></body>"
|
||
|
|
],
|
||
|
|
"text/plain": [
|
||
|
|
"HDBSCAN()"
|
||
|
|
]
|
||
|
|
},
|
||
|
|
"execution_count": 19,
|
||
|
|
"metadata": {},
|
||
|
|
"output_type": "execute_result"
|
||
|
|
}
|
||
|
|
],
|
||
|
|
"source": [
|
||
|
|
"%%time\n",
|
||
|
|
"clusterer = hdbscan.HDBSCAN()\n",
|
||
|
|
"clusterer.fit(X)"
|
||
|
|
]
|
||
|
|
},
|
||
|
|
{
|
||
|
|
"cell_type": "code",
|
||
|
|
"execution_count": 20,
|
||
|
|
"metadata": {
|
||
|
|
"colab": {
|
||
|
|
"base_uri": "https://localhost:8080/"
|
||
|
|
},
|
||
|
|
"id": "wrAzGgqrxHtY",
|
||
|
|
"outputId": "05493c84-d6cf-469a-e533-db36558c76ec"
|
||
|
|
},
|
||
|
|
"outputs": [
|
||
|
|
{
|
||
|
|
"name": "stdout",
|
||
|
|
"output_type": "stream",
|
||
|
|
"text": [
|
||
|
|
"0.7352694189002873\n"
|
||
|
|
]
|
||
|
|
}
|
||
|
|
],
|
||
|
|
"source": [
|
||
|
|
"print(silhouette_score(X, clusterer.labels_))"
|
||
|
|
]
|
||
|
|
},
|
||
|
|
{
|
||
|
|
"cell_type": "markdown",
|
||
|
|
"metadata": {
|
||
|
|
"id": "93qD18LqDiOj"
|
||
|
|
},
|
||
|
|
"source": [
|
||
|
|
"# Dimensionality Reduction"
|
||
|
|
]
|
||
|
|
},
|
||
|
|
{
|
||
|
|
"cell_type": "markdown",
|
||
|
|
"metadata": {
|
||
|
|
"id": "n0mwvzC0rdq4"
|
||
|
|
},
|
||
|
|
"source": [
|
||
|
|
"UMAP is a popular dimensionality reduction technique that is used for both data visualization and as preprocessing for downstream modeling due to its ability to balance preserving both local and global structure of high-dimensional data. To learn more about how it works, visit the [UMAP documentation](https://umap-learn.readthedocs.io/en/latest/).\n",
|
||
|
|
"\n",
|
||
|
|
"To explore how cuML can accelerate UMAP, let's load in another dataset from UCI. We'll use the Human Activity Recognition (HAR) dataset, which was created from recordings of 30 subjects performing activities of daily living (ADL) while carrying a waist-mounted smartphone with embedded inertial sensors."
|
||
|
|
]
|
||
|
|
},
|
||
|
|
{
|
||
|
|
"cell_type": "code",
|
||
|
|
"execution_count": null,
|
||
|
|
"metadata": {
|
||
|
|
"colab": {
|
||
|
|
"base_uri": "https://localhost:8080/"
|
||
|
|
},
|
||
|
|
"id": "JOeW2dt9D2IZ",
|
||
|
|
"outputId": "3f687e7c-8652-4b8e-bfc3-43cd1b291531"
|
||
|
|
},
|
||
|
|
"outputs": [],
|
||
|
|
"source": [
|
||
|
|
"!wget https://archive.ics.uci.edu/ml/machine-learning-databases/00240/UCI%20HAR%20Dataset.zip -O /tmp/HAR_data.zip"
|
||
|
|
]
|
||
|
|
},
|
||
|
|
{
|
||
|
|
"cell_type": "code",
|
||
|
|
"execution_count": null,
|
||
|
|
"metadata": {
|
||
|
|
"colab": {
|
||
|
|
"base_uri": "https://localhost:8080/"
|
||
|
|
},
|
||
|
|
"id": "TR78I9VuEGlu",
|
||
|
|
"outputId": "aad52a74-9c40-4be5-dc30-d6cda2b0f971"
|
||
|
|
},
|
||
|
|
"outputs": [],
|
||
|
|
"source": [
|
||
|
|
"!unzip /tmp/HAR_data.zip -d /tmp/HAR_data/"
|
||
|
|
]
|
||
|
|
},
|
||
|
|
{
|
||
|
|
"cell_type": "code",
|
||
|
|
"execution_count": 25,
|
||
|
|
"metadata": {
|
||
|
|
"id": "QjGw0WDwCu2_"
|
||
|
|
},
|
||
|
|
"outputs": [
|
||
|
|
{
|
||
|
|
"name": "stderr",
|
||
|
|
"output_type": "stream",
|
||
|
|
"text": [
|
||
|
|
"<>:3: SyntaxWarning: invalid escape sequence '\\s'\n",
|
||
|
|
"<>:4: SyntaxWarning: invalid escape sequence '\\s'\n",
|
||
|
|
"<>:5: SyntaxWarning: invalid escape sequence '\\s'\n",
|
||
|
|
"<>:6: SyntaxWarning: invalid escape sequence '\\s'\n",
|
||
|
|
"<>:7: SyntaxWarning: invalid escape sequence '\\s'\n",
|
||
|
|
"<>:3: SyntaxWarning: invalid escape sequence '\\s'\n",
|
||
|
|
"<>:4: SyntaxWarning: invalid escape sequence '\\s'\n",
|
||
|
|
"<>:5: SyntaxWarning: invalid escape sequence '\\s'\n",
|
||
|
|
"<>:6: SyntaxWarning: invalid escape sequence '\\s'\n",
|
||
|
|
"<>:7: SyntaxWarning: invalid escape sequence '\\s'\n",
|
||
|
|
"/tmp/ipykernel_238331/4099239257.py:3: SyntaxWarning: invalid escape sequence '\\s'\n",
|
||
|
|
" X_train = pd.read_csv(\"/tmp/HAR_data/UCI HAR Dataset/train/X_train.txt\", sep=\"\\s+\", header=None)\n",
|
||
|
|
"/tmp/ipykernel_238331/4099239257.py:4: SyntaxWarning: invalid escape sequence '\\s'\n",
|
||
|
|
" y_train = pd.read_csv(\"/tmp/HAR_data/UCI HAR Dataset/train/y_train.txt\", sep=\"\\s+\", header=None)\n",
|
||
|
|
"/tmp/ipykernel_238331/4099239257.py:5: SyntaxWarning: invalid escape sequence '\\s'\n",
|
||
|
|
" X_test = pd.read_csv(\"/tmp/HAR_data/UCI HAR Dataset/test/X_test.txt\", sep=\"\\s+\", header=None)\n",
|
||
|
|
"/tmp/ipykernel_238331/4099239257.py:6: SyntaxWarning: invalid escape sequence '\\s'\n",
|
||
|
|
" y_test = pd.read_csv(\"/tmp/HAR_data/UCI HAR Dataset/test/y_test.txt\", sep=\"\\s+\", header=None)\n",
|
||
|
|
"/tmp/ipykernel_238331/4099239257.py:7: SyntaxWarning: invalid escape sequence '\\s'\n",
|
||
|
|
" labels = pd.read_csv(\"/tmp/HAR_data/UCI HAR Dataset/activity_labels.txt\", sep=\"\\s+\", header=None)\n"
|
||
|
|
]
|
||
|
|
}
|
||
|
|
],
|
||
|
|
"source": [
|
||
|
|
"import pandas as pd\n",
|
||
|
|
"\n",
|
||
|
|
"X_train = pd.read_csv(\"/tmp/HAR_data/UCI HAR Dataset/train/X_train.txt\", sep=\"\\s+\", header=None)\n",
|
||
|
|
"y_train = pd.read_csv(\"/tmp/HAR_data/UCI HAR Dataset/train/y_train.txt\", sep=\"\\s+\", header=None)\n",
|
||
|
|
"X_test = pd.read_csv(\"/tmp/HAR_data/UCI HAR Dataset/test/X_test.txt\", sep=\"\\s+\", header=None)\n",
|
||
|
|
"y_test = pd.read_csv(\"/tmp/HAR_data/UCI HAR Dataset/test/y_test.txt\", sep=\"\\s+\", header=None)\n",
|
||
|
|
"labels = pd.read_csv(\"/tmp/HAR_data/UCI HAR Dataset/activity_labels.txt\", sep=\"\\s+\", header=None)"
|
||
|
|
]
|
||
|
|
},
|
||
|
|
{
|
||
|
|
"cell_type": "code",
|
||
|
|
"execution_count": 26,
|
||
|
|
"metadata": {
|
||
|
|
"colab": {
|
||
|
|
"base_uri": "https://localhost:8080/"
|
||
|
|
},
|
||
|
|
"id": "oesYc97pQ1vr",
|
||
|
|
"outputId": "e7dca260-5abb-4f27-d61e-e336955b5271"
|
||
|
|
},
|
||
|
|
"outputs": [
|
||
|
|
{
|
||
|
|
"data": {
|
||
|
|
"text/plain": [
|
||
|
|
"(7352, 561)"
|
||
|
|
]
|
||
|
|
},
|
||
|
|
"execution_count": 26,
|
||
|
|
"metadata": {},
|
||
|
|
"output_type": "execute_result"
|
||
|
|
}
|
||
|
|
],
|
||
|
|
"source": [
|
||
|
|
"X_train.shape"
|
||
|
|
]
|
||
|
|
},
|
||
|
|
{
|
||
|
|
"cell_type": "markdown",
|
||
|
|
"metadata": {
|
||
|
|
"id": "F5Cle6mGOH7S"
|
||
|
|
},
|
||
|
|
"source": [
|
||
|
|
"Let's take a look at the activity labels to better understand the data we're working with. We can see that the sensors have grouped activities into 6 different classes."
|
||
|
|
]
|
||
|
|
},
|
||
|
|
{
|
||
|
|
"cell_type": "code",
|
||
|
|
"execution_count": 27,
|
||
|
|
"metadata": {
|
||
|
|
"colab": {
|
||
|
|
"base_uri": "https://localhost:8080/",
|
||
|
|
"height": 238
|
||
|
|
},
|
||
|
|
"id": "22YYMRvXOUUz",
|
||
|
|
"outputId": "b15af6d7-8c52-474e-f102-f573dd7f2d2e"
|
||
|
|
},
|
||
|
|
"outputs": [
|
||
|
|
{
|
||
|
|
"data": {
|
||
|
|
"text/html": [
|
||
|
|
"<div>\n",
|
||
|
|
"<style scoped>\n",
|
||
|
|
" .dataframe tbody tr th:only-of-type {\n",
|
||
|
|
" vertical-align: middle;\n",
|
||
|
|
" }\n",
|
||
|
|
"\n",
|
||
|
|
" .dataframe tbody tr th {\n",
|
||
|
|
" vertical-align: top;\n",
|
||
|
|
" }\n",
|
||
|
|
"\n",
|
||
|
|
" .dataframe thead th {\n",
|
||
|
|
" text-align: right;\n",
|
||
|
|
" }\n",
|
||
|
|
"</style>\n",
|
||
|
|
"<table border=\"1\" class=\"dataframe\">\n",
|
||
|
|
" <thead>\n",
|
||
|
|
" <tr style=\"text-align: right;\">\n",
|
||
|
|
" <th></th>\n",
|
||
|
|
" <th>0</th>\n",
|
||
|
|
" <th>1</th>\n",
|
||
|
|
" </tr>\n",
|
||
|
|
" </thead>\n",
|
||
|
|
" <tbody>\n",
|
||
|
|
" <tr>\n",
|
||
|
|
" <th>0</th>\n",
|
||
|
|
" <td>1</td>\n",
|
||
|
|
" <td>WALKING</td>\n",
|
||
|
|
" </tr>\n",
|
||
|
|
" <tr>\n",
|
||
|
|
" <th>1</th>\n",
|
||
|
|
" <td>2</td>\n",
|
||
|
|
" <td>WALKING_UPSTAIRS</td>\n",
|
||
|
|
" </tr>\n",
|
||
|
|
" <tr>\n",
|
||
|
|
" <th>2</th>\n",
|
||
|
|
" <td>3</td>\n",
|
||
|
|
" <td>WALKING_DOWNSTAIRS</td>\n",
|
||
|
|
" </tr>\n",
|
||
|
|
" <tr>\n",
|
||
|
|
" <th>3</th>\n",
|
||
|
|
" <td>4</td>\n",
|
||
|
|
" <td>SITTING</td>\n",
|
||
|
|
" </tr>\n",
|
||
|
|
" <tr>\n",
|
||
|
|
" <th>4</th>\n",
|
||
|
|
" <td>5</td>\n",
|
||
|
|
" <td>STANDING</td>\n",
|
||
|
|
" </tr>\n",
|
||
|
|
" <tr>\n",
|
||
|
|
" <th>5</th>\n",
|
||
|
|
" <td>6</td>\n",
|
||
|
|
" <td>LAYING</td>\n",
|
||
|
|
" </tr>\n",
|
||
|
|
" </tbody>\n",
|
||
|
|
"</table>\n",
|
||
|
|
"</div>"
|
||
|
|
],
|
||
|
|
"text/plain": [
|
||
|
|
" 0 1\n",
|
||
|
|
"0 1 WALKING\n",
|
||
|
|
"1 2 WALKING_UPSTAIRS\n",
|
||
|
|
"2 3 WALKING_DOWNSTAIRS\n",
|
||
|
|
"3 4 SITTING\n",
|
||
|
|
"4 5 STANDING\n",
|
||
|
|
"5 6 LAYING"
|
||
|
|
]
|
||
|
|
},
|
||
|
|
"execution_count": 27,
|
||
|
|
"metadata": {},
|
||
|
|
"output_type": "execute_result"
|
||
|
|
}
|
||
|
|
],
|
||
|
|
"source": [
|
||
|
|
"labels"
|
||
|
|
]
|
||
|
|
},
|
||
|
|
{
|
||
|
|
"cell_type": "code",
|
||
|
|
"execution_count": 28,
|
||
|
|
"metadata": {
|
||
|
|
"id": "8rA7SsEpCu5M"
|
||
|
|
},
|
||
|
|
"outputs": [],
|
||
|
|
"source": [
|
||
|
|
"from sklearn.preprocessing import StandardScaler\n",
|
||
|
|
"\n",
|
||
|
|
"# Scale the data before applying UMAP\n",
|
||
|
|
"scaler = StandardScaler()\n",
|
||
|
|
"X_train_scaled = scaler.fit_transform(X_train)\n"
|
||
|
|
]
|
||
|
|
},
|
||
|
|
{
|
||
|
|
"cell_type": "markdown",
|
||
|
|
"metadata": {
|
||
|
|
"id": "_9ltJhG7tQt0"
|
||
|
|
},
|
||
|
|
"source": [
|
||
|
|
"Let's run UMAP with some basic parameters and explore a lower-dimensionality projection of this dataset."
|
||
|
|
]
|
||
|
|
},
|
||
|
|
{
|
||
|
|
"cell_type": "code",
|
||
|
|
"execution_count": 29,
|
||
|
|
"metadata": {
|
||
|
|
"id": "t4sR7x3sF_9a"
|
||
|
|
},
|
||
|
|
"outputs": [],
|
||
|
|
"source": [
|
||
|
|
"import umap\n",
|
||
|
|
"umap_model = umap.UMAP(n_neighbors=15, n_components=2, random_state=42, min_dist=0.0)"
|
||
|
|
]
|
||
|
|
},
|
||
|
|
{
|
||
|
|
"cell_type": "code",
|
||
|
|
"execution_count": null,
|
||
|
|
"metadata": {
|
||
|
|
"colab": {
|
||
|
|
"base_uri": "https://localhost:8080/"
|
||
|
|
},
|
||
|
|
"id": "cGD49PFVlyrz",
|
||
|
|
"outputId": "81f5a19c-d2c6-498c-c673-facc3ced964d"
|
||
|
|
},
|
||
|
|
"outputs": [
|
||
|
|
{
|
||
|
|
"name": "stdout",
|
||
|
|
"output_type": "stream",
|
||
|
|
"text": [
|
||
|
|
"[2025-10-05 21:26:31.169] [CUML] [info] build_algo set to brute_force_knn because random_state is given\n",
|
||
|
|
"CPU times: user 170 ms, sys: 61.5 ms, total: 232 ms\n",
|
||
|
|
"Wall time: 481 ms\n"
|
||
|
|
]
|
||
|
|
}
|
||
|
|
],
|
||
|
|
"source": [
|
||
|
|
"%%time\n",
|
||
|
|
"# Fit UMAP model to the data\n",
|
||
|
|
"X_train_umap = umap_model.fit_transform(X_train_scaled)"
|
||
|
|
]
|
||
|
|
},
|
||
|
|
{
|
||
|
|
"cell_type": "markdown",
|
||
|
|
"metadata": {
|
||
|
|
"id": "kwJC2woSl4U9"
|
||
|
|
},
|
||
|
|
"source": [
|
||
|
|
"It's often quite interesting to visualize the resulting projection of the embeddings created by UMAP. In this case, let's take a look at the now 2-dimensional dataset."
|
||
|
|
]
|
||
|
|
},
|
||
|
|
{
|
||
|
|
"cell_type": "code",
|
||
|
|
"execution_count": 31,
|
||
|
|
"metadata": {
|
||
|
|
"colab": {
|
||
|
|
"base_uri": "https://localhost:8080/",
|
||
|
|
"height": 718
|
||
|
|
},
|
||
|
|
"id": "PDRxaBEdF__X",
|
||
|
|
"outputId": "2ddd2b8b-8b1a-48e4-e06b-b5ffe0245f27"
|
||
|
|
},
|
||
|
|
"outputs": [
|
||
|
|
{
|
||
|
|
"data": {
|
||
|
|
"image/png": "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
|
||
|
|
"text/plain": [
|
||
|
|
"<Figure size 1000x800 with 2 Axes>"
|
||
|
|
]
|
||
|
|
},
|
||
|
|
"metadata": {},
|
||
|
|
"output_type": "display_data"
|
||
|
|
}
|
||
|
|
],
|
||
|
|
"source": [
|
||
|
|
"import matplotlib.pyplot as plt\n",
|
||
|
|
"\n",
|
||
|
|
"# Plot the UMAP result\n",
|
||
|
|
"plt.figure(figsize=(10, 8))\n",
|
||
|
|
"plt.scatter(X_train_umap[:, 0], X_train_umap[:, 1], c=y_train.values.ravel(), cmap='Spectral', s=10)\n",
|
||
|
|
"plt.colorbar(label=\"Activity\")\n",
|
||
|
|
"plt.title(\"UMAP projection of the UCI HAR dataset\")\n",
|
||
|
|
"plt.xlabel(\"UMAP Component 1\")\n",
|
||
|
|
"plt.ylabel(\"UMAP Component 2\")\n",
|
||
|
|
"plt.show()\n"
|
||
|
|
]
|
||
|
|
},
|
||
|
|
{
|
||
|
|
"cell_type": "markdown",
|
||
|
|
"metadata": {
|
||
|
|
"id": "gKFBLuE7mFrs"
|
||
|
|
},
|
||
|
|
"source": [
|
||
|
|
"It's interesting to see how our different categories are grouped in relation to one another.\n",
|
||
|
|
"\n",
|
||
|
|
"We can look at the trustworthiness score to better understand how well the structure of the original dataset was preserved by our 2D projection"
|
||
|
|
]
|
||
|
|
},
|
||
|
|
{
|
||
|
|
"cell_type": "code",
|
||
|
|
"execution_count": 32,
|
||
|
|
"metadata": {
|
||
|
|
"colab": {
|
||
|
|
"base_uri": "https://localhost:8080/"
|
||
|
|
},
|
||
|
|
"id": "Say1EIdqMLoq",
|
||
|
|
"outputId": "3c3f1623-8ef2-4703-9dcb-1e2ba3e148d7"
|
||
|
|
},
|
||
|
|
"outputs": [
|
||
|
|
{
|
||
|
|
"data": {
|
||
|
|
"text/plain": [
|
||
|
|
"np.float64(0.9709711206340002)"
|
||
|
|
]
|
||
|
|
},
|
||
|
|
"execution_count": 32,
|
||
|
|
"metadata": {},
|
||
|
|
"output_type": "execute_result"
|
||
|
|
}
|
||
|
|
],
|
||
|
|
"source": [
|
||
|
|
"from sklearn.manifold import trustworthiness\n",
|
||
|
|
"trustworthiness(X_train, X_train_umap, n_neighbors=15)"
|
||
|
|
]
|
||
|
|
},
|
||
|
|
{
|
||
|
|
"cell_type": "markdown",
|
||
|
|
"metadata": {
|
||
|
|
"id": "1OzvVajcm2jX"
|
||
|
|
},
|
||
|
|
"source": [
|
||
|
|
"It looks like this projection is a great representation of our full dataset.\n",
|
||
|
|
"\n",
|
||
|
|
"Let's now run the same thing with the accelerator turned on."
|
||
|
|
]
|
||
|
|
}
|
||
|
|
],
|
||
|
|
"metadata": {
|
||
|
|
"accelerator": "GPU",
|
||
|
|
"colab": {
|
||
|
|
"gpuType": "T4",
|
||
|
|
"provenance": []
|
||
|
|
},
|
||
|
|
"kernelspec": {
|
||
|
|
"display_name": "rapids-25.10",
|
||
|
|
"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.12.11"
|
||
|
|
}
|
||
|
|
},
|
||
|
|
"nbformat": 4,
|
||
|
|
"nbformat_minor": 4
|
||
|
|
}
|