{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "c000",
   "metadata": {},
   "source": [
    "# Nearest Neighbors with scikit-learn"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "c001",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2026-11-17T23:43:41.106832Z",
     "iopub.status.busy": "2026-11-17T23:43:41.106729Z",
     "iopub.status.idle": "2026-11-17T23:43:42.456411Z",
     "shell.execute_reply": "2026-11-17T23:43:42.455971Z"
    },
    "tags": [
     "hide-input",
     "thebe-init",
     "runnable"
    ]
   },
   "outputs": [],
   "source": [
    "path_data = '../../data/'\n",
    "\n",
    "import numpy as np\n",
    "import pandas as pd\n",
    "\n",
    "import matplotlib.pyplot as plt\n",
    "plt.style.use('fivethirtyeight')\n",
    "%matplotlib inline\n",
    "\n",
    "from sklearn.model_selection import train_test_split\n",
    "from sklearn.preprocessing import StandardScaler\n",
    "from sklearn.neighbors import KNeighborsClassifier\n",
    "from sklearn.pipeline import make_pipeline\n",
    "from sklearn.metrics import accuracy_score"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "c003",
   "metadata": {},
   "source": [
    "In Chapter 14 you built a $k$-nearest neighbor classifier by hand ({doc}`../14-classification/1402-nearest-neighbors`): compute distances, sort, take the $k$ closest rows, and hold a majority vote. That code shows exactly what the method does, but it is slow and easy to get wrong. In practice, analysts use a library. In Chapter 13 you used scikit-learn's `LinearRegression` and `KNeighborsRegressor`; scikit-learn's `KNeighborsClassifier` does the same work for classification, with the same `fit` and `predict` steps.\n",
    "\n",
    "This section follows one business case through the whole workflow, using the online shopping sessions from Sections {doc}`../14-classification/1401-classification` to {doc}`../14-classification/1403-training-testing-accuracy`. An online retailer wants to know **which sessions are likely to end in a purchase**, so that it can send a nudge, such as a reminder email or a free-shipping offer, to those visitors before they leave. The steps are the ones you already know from the hand-built classifier:\n",
    "\n",
    "1. Choose the features and the target.\n",
    "2. Split the data into a training set and a test set.\n",
    "3. Put the features on a common scale, using the training set only.\n",
    "4. Fit the classifier, predict, and measure accuracy on the test set.\n",
    "5. Choose $k$ by comparing accuracy on data the classifier has not seen."
   ]
  },
  {
   "cell_type": "markdown",
   "id": "c002",
   "metadata": {},
   "source": [
    "```{contents}\n",
    ":local:\n",
    ":depth: 2\n",
    "```"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "c004",
   "metadata": {},
   "source": [
    "## The Shopping Session Data\n",
    "\n",
    "```{index} online shoppers data; scikit-learn workflow\n",
    "```\n",
    "\n",
    "```{index} purchase rate\n",
    "```\n",
    "\n",
    "The file `online_shoppers.csv` is the real data set introduced in Section {doc}`../14-classification/1401-classification`: 12,330 sessions on an online retailer's website over one year, from the UCI Machine Learning Repository (Sakar and others, 2019; CC BY 4.0). Each row is one session. This section uses three numeric attributes and the label:\n",
    "\n",
    "- `page_value`: the average dollar value of the pages the visitor saw, computed by the retailer's analytics tool from the sales that followed visits to those pages,\n",
    "- `exit_rate`: how often visits to the pages the visitor saw ended there,\n",
    "- `product_pages`: the number of product pages the visitor viewed,\n",
    "- `outcome`: `purchase` if the session ended in a purchase, `no purchase` otherwise."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "c005",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2026-11-17T23:43:42.457826Z",
     "iopub.status.busy": "2026-11-17T23:43:42.457719Z",
     "iopub.status.idle": "2026-11-17T23:43:42.474902Z",
     "shell.execute_reply": "2026-11-17T23:43:42.474539Z"
    },
    "tags": []
   },
   "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>page_value</th>\n",
       "      <th>exit_rate</th>\n",
       "      <th>product_pages</th>\n",
       "      <th>outcome</th>\n",
       "      <th>purchase</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>0.0</td>\n",
       "      <td>0.20</td>\n",
       "      <td>1</td>\n",
       "      <td>no purchase</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>0.0</td>\n",
       "      <td>0.10</td>\n",
       "      <td>2</td>\n",
       "      <td>no purchase</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>0.0</td>\n",
       "      <td>0.20</td>\n",
       "      <td>1</td>\n",
       "      <td>no purchase</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>0.0</td>\n",
       "      <td>0.14</td>\n",
       "      <td>2</td>\n",
       "      <td>no purchase</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>0.0</td>\n",
       "      <td>0.05</td>\n",
       "      <td>10</td>\n",
       "      <td>no purchase</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   page_value  exit_rate  product_pages      outcome  purchase\n",
       "0         0.0       0.20              1  no purchase         0\n",
       "1         0.0       0.10              2  no purchase         0\n",
       "2         0.0       0.20              1  no purchase         0\n",
       "3         0.0       0.14              2  no purchase         0\n",
       "4         0.0       0.05             10  no purchase         0"
      ]
     },
     "execution_count": 2,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "shoppers = pd.read_csv(path_data + 'online_shoppers.csv')\n",
    "\n",
    "# scikit-learn works with numbers, so make a 0/1 label: 1 means the session ended in a purchase.\n",
    "shoppers['purchase'] = (shoppers['outcome'] == 'purchase').astype(int)\n",
    "shoppers[['page_value', 'exit_rate', 'product_pages', 'outcome', 'purchase']].head()"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "c006",
   "metadata": {},
   "source": [
    "How common is a purchase? The `value_counts` method with `normalize=True` gives the proportion of sessions in each class."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "c007",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2026-11-17T23:43:42.475919Z",
     "iopub.status.busy": "2026-11-17T23:43:42.475851Z",
     "iopub.status.idle": "2026-11-17T23:43:42.479054Z",
     "shell.execute_reply": "2026-11-17T23:43:42.478797Z"
    },
    "tags": []
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "purchase\n",
       "0    0.845255\n",
       "1    0.154745\n",
       "Name: proportion, dtype: float64"
      ]
     },
     "execution_count": 3,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "shoppers['purchase'].value_counts(normalize=True)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "c008",
   "metadata": {},
   "source": [
    "About 15% of the sessions ended in a purchase and 85% did not. The classes are *imbalanced*: one class is much more common than the other. Keep that 85% in mind. A \"classifier\" that predicts \"no purchase\" for every session, without looking at any data, is already right about 85% of the time, so a real classifier has to beat that.\n",
    "\n",
    "Comparing the average attributes of the two groups shows why the features should help."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "id": "c009",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2026-11-17T23:43:42.480047Z",
     "iopub.status.busy": "2026-11-17T23:43:42.479989Z",
     "iopub.status.idle": "2026-11-17T23:43:42.484536Z",
     "shell.execute_reply": "2026-11-17T23:43:42.484220Z"
    },
    "tags": []
   },
   "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>page_value</th>\n",
       "      <th>exit_rate</th>\n",
       "      <th>product_pages</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>purchase</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>1.975998</td>\n",
       "      <td>0.047378</td>\n",
       "      <td>28.714642</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>27.264518</td>\n",
       "      <td>0.019555</td>\n",
       "      <td>48.210168</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "          page_value  exit_rate  product_pages\n",
       "purchase                                      \n",
       "0           1.975998   0.047378      28.714642\n",
       "1          27.264518   0.019555      48.210168"
      ]
     },
     "execution_count": 4,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "shoppers.groupby('purchase')[['page_value', 'exit_rate', 'product_pages']].mean()"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "c010",
   "metadata": {},
   "source": [
    "Sessions that ended in a purchase had an average page value of about \\$27, compared with about \\$2 for sessions that did not. Their exit rate was less than half as high (0.020 against 0.047), and they viewed more product pages (48 against 29 on average). These are the same patterns you saw in Section {doc}`../14-classification/1401-classification`."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "id": "c011",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2026-11-17T23:43:42.485372Z",
     "iopub.status.busy": "2026-11-17T23:43:42.485314Z",
     "iopub.status.idle": "2026-11-17T23:43:42.491701Z",
     "shell.execute_reply": "2026-11-17T23:43:42.491367Z"
    },
    "tags": [
     "thebe-interactive"
    ]
   },
   "outputs": [],
   "source": [
    "### Exercise: Purchase Rate by Visitor Type\n",
    "#   1. Split the shoppers table into new visitors (visitor_type 'New_Visitor') and\n",
    "#      returning visitors (visitor_type 'Returning_Visitor').\n",
    "#   2. Compute the purchase rate (the share of sessions with outcome 'purchase') for\n",
    "#      each group, rounded to 3 decimals.\n",
    "# Print exactly:\n",
    "# Purchase rate, new visitors: 0.249\n",
    "# Purchase rate, returning visitors: 0.139\n",
    "ex_visitors = pd.read_csv(path_data + 'online_shoppers.csv')\n",
    "### Your code starts here.\n",
    "\n",
    "\n",
    "\n",
    "\n",
    "### Your code ends here."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "id": "c012",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2026-11-17T23:43:42.492723Z",
     "iopub.status.busy": "2026-11-17T23:43:42.492661Z",
     "iopub.status.idle": "2026-11-17T23:43:42.501739Z",
     "shell.execute_reply": "2026-11-17T23:43:42.501452Z"
    },
    "tags": [
     "hide-input"
    ]
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Purchase rate, new visitors: 0.249\n",
      "Purchase rate, returning visitors: 0.139\n"
     ]
    }
   ],
   "source": [
    "### Solution\n",
    "ex_visitors = pd.read_csv(path_data + 'online_shoppers.csv')\n",
    "\n",
    "ex_new = ex_visitors[ex_visitors['visitor_type'] == 'New_Visitor']\n",
    "ex_returning = ex_visitors[ex_visitors['visitor_type'] == 'Returning_Visitor']\n",
    "\n",
    "print('Purchase rate, new visitors:', round((ex_new['outcome'] == 'purchase').mean(), 3))\n",
    "print('Purchase rate, returning visitors:', round((ex_returning['outcome'] == 'purchase').mean(), 3))"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "c013",
   "metadata": {},
   "source": [
    "## Features, Target, and a Train-Test Split\n",
    "\n",
    "```{index} feature matrix; classification\n",
    "```\n",
    "\n",
    "```{index} target variable\n",
    "```\n",
    "\n",
    "```{index} train_test_split; classification\n",
    "```\n",
    "\n",
    "```{index} stratified split\n",
    "```\n",
    "\n",
    "As in Chapter 13, scikit-learn expects the inputs in two pieces:\n",
    "\n",
    "- `X`, a table of **features** (one column per attribute the classifier may use), and\n",
    "- `y`, the **target**: the column of labels to predict.\n",
    "\n",
    "The other columns, such as `month` and `weekend`, are not numbers on a common footing with these three, so they are left out to keep the example simple."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "id": "c014",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2026-11-17T23:43:42.502692Z",
     "iopub.status.busy": "2026-11-17T23:43:42.502634Z",
     "iopub.status.idle": "2026-11-17T23:43:42.504637Z",
     "shell.execute_reply": "2026-11-17T23:43:42.504343Z"
    },
    "tags": []
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "((12330, 3), (12330,))"
      ]
     },
     "execution_count": 7,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "features = ['page_value', 'exit_rate', 'product_pages']\n",
    "\n",
    "X = shoppers[features]\n",
    "y = shoppers['purchase']\n",
    "\n",
    "X.shape, y.shape"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "c015",
   "metadata": {},
   "source": [
    "Next, hold out a test set. Section {doc}`../14-classification/1403-training-testing-accuracy` did this by shuffling the rows and cutting the table in two; `train_test_split` does both steps at once. Keep 30% of the sessions for testing and fix `random_state` so the split is the same every time the page runs.\n",
    "\n",
    "The argument `stratify=y` asks for a *stratified* split: the training and test sets keep the same share of purchases as the full data. With imbalanced classes this matters, because an unlucky random split could leave the test set with too few purchases to judge the classifier."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "id": "c016",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2026-11-17T23:43:42.505461Z",
     "iopub.status.busy": "2026-11-17T23:43:42.505412Z",
     "iopub.status.idle": "2026-11-17T23:43:42.522358Z",
     "shell.execute_reply": "2026-11-17T23:43:42.521927Z"
    },
    "tags": []
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "8631 training sessions and 3699 test sessions\n",
      "Purchase rate in training set: 0.155\n",
      "Purchase rate in test set: 0.155\n"
     ]
    }
   ],
   "source": [
    "X_train, X_test, y_train, y_test = train_test_split(\n",
    "    X, y, test_size=0.3, random_state=14, stratify=y)\n",
    "\n",
    "print(len(X_train), 'training sessions and', len(X_test), 'test sessions')\n",
    "print('Purchase rate in training set:', round(y_train.mean(), 3))\n",
    "print('Purchase rate in test set:', round(y_test.mean(), 3))"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "c017",
   "metadata": {},
   "source": [
    "Both sets have a purchase rate of about 0.155, the same as the full data. From here on, the test set stays locked away until you are ready to report how well the final classifier works."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "id": "c018",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2026-11-17T23:43:42.523568Z",
     "iopub.status.busy": "2026-11-17T23:43:42.523491Z",
     "iopub.status.idle": "2026-11-17T23:43:42.525086Z",
     "shell.execute_reply": "2026-11-17T23:43:42.524773Z"
    },
    "tags": [
     "thebe-interactive"
    ]
   },
   "outputs": [],
   "source": [
    "### Exercise: A Different Split\n",
    "#   1. Split X and y again, this time keeping 20% for testing.\n",
    "#      Use random_state=1 and stratify=y.\n",
    "#   2. Print the number of training and test sessions and the purchase rate of the\n",
    "#      test set, rounded to 3 decimals.\n",
    "# Print exactly:\n",
    "# Training: 9864\n",
    "# Test: 2466\n",
    "# Test purchase rate: 0.155\n",
    "### Your code starts here.\n",
    "\n",
    "\n",
    "\n",
    "\n",
    "### Your code ends here."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "id": "c019",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2026-11-17T23:43:42.525890Z",
     "iopub.status.busy": "2026-11-17T23:43:42.525839Z",
     "iopub.status.idle": "2026-11-17T23:43:42.529675Z",
     "shell.execute_reply": "2026-11-17T23:43:42.529393Z"
    },
    "tags": [
     "hide-input"
    ]
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Training: 9864\n",
      "Test: 2466\n",
      "Test purchase rate: 0.155\n"
     ]
    }
   ],
   "source": [
    "### Solution\n",
    "ex_X_train, ex_X_test, ex_y_train, ex_y_test = train_test_split(\n",
    "    X, y, test_size=0.2, random_state=1, stratify=y)\n",
    "\n",
    "print('Training:', len(ex_X_train))\n",
    "print('Test:', len(ex_X_test))\n",
    "print('Test purchase rate:', round(ex_y_test.mean(), 3))"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "c020",
   "metadata": {},
   "source": [
    "## Scaling Features with StandardScaler\n",
    "\n",
    "```{index} StandardScaler\n",
    "```\n",
    "\n",
    "```{index} scaling features; scikit-learn\n",
    "```\n",
    "\n",
    "```{index} standard units; StandardScaler\n",
    "```\n",
    "\n",
    "Distance adds up the squared differences in every feature. The features have very different scales: page value runs from \\$0 to about \\$360, the exit rate from 0 to 0.2, and the number of product pages from 0 to 705. Without scaling, a difference of one product page counts as much as a difference of one dollar of page value, even though page value is the strongest sign of a purchase and the number of pages is spread over a far wider range.\n",
    "\n",
    "In Sections {doc}`../14-classification/1402-nearest-neighbors` and {doc}`../14-classification/1403-training-testing-accuracy` you converted each feature to standard units by subtracting its mean and dividing by its SD. scikit-learn's `StandardScaler` does the same thing. It works in two steps:\n",
    "\n",
    "- `fit` learns the mean and SD of each feature. **Fit on the training set only**, for the reason given in Section {doc}`../14-classification/1403-training-testing-accuracy`: the test sessions stand in for future sessions, so they must not influence how the classifier is built.\n",
    "- `transform` applies those training means and SDs to any table: the training set, the test set, or a brand-new session."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "id": "c021",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2026-11-17T23:43:42.530704Z",
     "iopub.status.busy": "2026-11-17T23:43:42.530649Z",
     "iopub.status.idle": "2026-11-17T23:43:42.534425Z",
     "shell.execute_reply": "2026-11-17T23:43:42.534034Z"
    },
    "tags": []
   },
   "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>mean</th>\n",
       "      <th>SD</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>page_value</th>\n",
       "      <td>5.818068</td>\n",
       "      <td>18.931328</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>exit_rate</th>\n",
       "      <td>0.043343</td>\n",
       "      <td>0.048874</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>product_pages</th>\n",
       "      <td>31.541768</td>\n",
       "      <td>44.043043</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                    mean         SD\n",
       "page_value      5.818068  18.931328\n",
       "exit_rate       0.043343   0.048874\n",
       "product_pages  31.541768  44.043043"
      ]
     },
     "execution_count": 11,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "scaler = StandardScaler()\n",
    "scaler.fit(X_train)\n",
    "\n",
    "pd.DataFrame({'mean': scaler.mean_, 'SD': scaler.scale_}, index=features)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "id": "c022",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2026-11-17T23:43:42.535836Z",
     "iopub.status.busy": "2026-11-17T23:43:42.535726Z",
     "iopub.status.idle": "2026-11-17T23:43:42.540426Z",
     "shell.execute_reply": "2026-11-17T23:43:42.539618Z"
    },
    "tags": []
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[-0.31, -0.26, -0.19],\n",
       "       [ 0.18, -0.64,  4.39],\n",
       "       [-0.31,  0.07, -0.49],\n",
       "       [-0.28, -0.59,  4.76],\n",
       "       [ 0.06, -0.61,  6.39]])"
      ]
     },
     "execution_count": 12,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "X_train_scaled = scaler.transform(X_train)\n",
    "X_test_scaled = scaler.transform(X_test)\n",
    "\n",
    "X_train_scaled[:5].round(2)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "c023",
   "metadata": {},
   "source": [
    "The result is a NumPy array in standard units. Each column of the scaled *training* set now has mean 0 and SD 1. The scaled *test* set has means and SDs close to, but not exactly, 0 and 1, because it was scaled with the training statistics, which is what you want."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "id": "c024",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2026-11-17T23:43:42.543516Z",
     "iopub.status.busy": "2026-11-17T23:43:42.543304Z",
     "iopub.status.idle": "2026-11-17T23:43:42.547705Z",
     "shell.execute_reply": "2026-11-17T23:43:42.547084Z"
    },
    "tags": []
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Training means: [0. 0. 0.]\n",
      "Training SDs:   [1. 1. 1.]\n",
      "Test means:     [ 0.01 -0.02  0.01]\n",
      "Test SDs:       [0.93 0.98 1.03]\n"
     ]
    }
   ],
   "source": [
    "print('Training means:', X_train_scaled.mean(axis=0).round(2) + 0)\n",
    "print('Training SDs:  ', X_train_scaled.std(axis=0).round(2))\n",
    "print('Test means:    ', X_test_scaled.mean(axis=0).round(2))\n",
    "print('Test SDs:      ', X_test_scaled.std(axis=0).round(2))"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "c025",
   "metadata": {},
   "source": [
    "A new session is scaled the same way. Here is a session in which the visitor has viewed 30 product pages, the pages seen have a page value of \\$12, and the exit rate is 0.02."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "id": "c026",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2026-11-17T23:43:42.550239Z",
     "iopub.status.busy": "2026-11-17T23:43:42.550151Z",
     "iopub.status.idle": "2026-11-17T23:43:42.553039Z",
     "shell.execute_reply": "2026-11-17T23:43:42.552716Z"
    },
    "tags": []
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[ 0.33, -0.48, -0.04]])"
      ]
     },
     "execution_count": 14,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "new_session = pd.DataFrame({'page_value': [12.0],\n",
    "                            'exit_rate': [0.02],\n",
    "                            'product_pages': [30]})\n",
    "\n",
    "scaler.transform(new_session).round(2)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "c027",
   "metadata": {},
   "source": [
    "In standard units, this session's page value is a third of an SD above average, its exit rate is about half an SD below average, and its number of product pages is almost exactly average."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "id": "c028",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2026-11-17T23:43:42.554019Z",
     "iopub.status.busy": "2026-11-17T23:43:42.553942Z",
     "iopub.status.idle": "2026-11-17T23:43:42.555457Z",
     "shell.execute_reply": "2026-11-17T23:43:42.555113Z"
    },
    "tags": [
     "thebe-interactive"
    ]
   },
   "outputs": [],
   "source": [
    "### Exercise: Scale a New Session\n",
    "#   1. Put a session with page_value 0.0, exit_rate 0.1, and product_pages 10\n",
    "#      in a one-row DataFrame with the columns in features.\n",
    "#   2. Use the scaler fitted above (do not refit it) to convert the session to\n",
    "#      standard units, and print the result rounded to 2 decimals.\n",
    "# Print exactly:\n",
    "# [[-0.31  1.16 -0.49]]\n",
    "### Your code starts here.\n",
    "\n",
    "\n",
    "\n",
    "\n",
    "### Your code ends here."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "id": "c029",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2026-11-17T23:43:42.556843Z",
     "iopub.status.busy": "2026-11-17T23:43:42.556757Z",
     "iopub.status.idle": "2026-11-17T23:43:42.559243Z",
     "shell.execute_reply": "2026-11-17T23:43:42.558936Z"
    },
    "tags": [
     "hide-input"
    ]
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[[-0.31  1.16 -0.49]]\n"
     ]
    }
   ],
   "source": [
    "### Solution\n",
    "ex_session = pd.DataFrame({'page_value': [0.0],\n",
    "                           'exit_rate': [0.1],\n",
    "                           'product_pages': [10]})\n",
    "\n",
    "print(scaler.transform(ex_session).round(2))"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "c030",
   "metadata": {},
   "source": [
    "## Fitting and Predicting with KNeighborsClassifier\n",
    "\n",
    "```{index} KNeighborsClassifier\n",
    "```\n",
    "\n",
    "```{index} fit; classifier\n",
    "```\n",
    "\n",
    "```{index} predict; classifier\n",
    "```\n",
    "\n",
    "```{index} accuracy_score\n",
    "```\n",
    "\n",
    "`KNeighborsClassifier` is scikit-learn's $k$-nearest neighbor classifier. The argument `n_neighbors` is $k$. Fitting a nearest neighbor classifier does very little work: `fit` simply stores the training rows and their labels. The real work happens in `predict`, which, for each new row, finds the $k$ nearest training rows and takes a majority vote, exactly like the `classify` function you wrote in Section {doc}`../14-classification/1402-nearest-neighbors`."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "id": "c031",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2026-11-17T23:43:42.560152Z",
     "iopub.status.busy": "2026-11-17T23:43:42.560099Z",
     "iopub.status.idle": "2026-11-17T23:43:42.568681Z",
     "shell.execute_reply": "2026-11-17T23:43:42.568211Z"
    },
    "tags": []
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<style>.sk-global {\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",
       "\n",
       ".sk-global.light {\n",
       "  /* Specific color for light theme */\n",
       "  --sklearn-color-text-on-default-background: black;\n",
       "  --sklearn-color-background: white;\n",
       "  --sklearn-color-border-box: black;\n",
       "  --sklearn-color-icon: #696969;\n",
       "}\n",
       "\n",
       ".sk-global.dark {\n",
       "  --sklearn-color-text-on-default-background: white;\n",
       "  --sklearn-color-background: #111;\n",
       "  --sklearn-color-border-box: white;\n",
       "  --sklearn-color-icon: #878787;\n",
       "}\n",
       "\n",
       ".sk-global {\n",
       "  color: var(--sklearn-color-text);\n",
       "}\n",
       "\n",
       ".sk-global pre {\n",
       "  padding: 0;\n",
       "}\n",
       "\n",
       ".sk-global input.sk-hidden--visually {\n",
       "  border: 0;\n",
       "  clip-path: inset(100%);\n",
       "  height: 1px;\n",
       "  margin: -1px;\n",
       "  overflow: hidden;\n",
       "  padding: 0;\n",
       "  position: absolute;\n",
       "  width: 1px;\n",
       "}\n",
       "\n",
       ".sk-global 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-global 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-global 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-global 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-global 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-global div.sk-parallel-item {\n",
       "  display: flex;\n",
       "  flex-direction: column;\n",
       "}\n",
       "\n",
       ".sk-global div.sk-parallel-item:first-child::after {\n",
       "  align-self: flex-end;\n",
       "  width: 50%;\n",
       "}\n",
       "\n",
       ".sk-global div.sk-parallel-item:last-child::after {\n",
       "  align-self: flex-start;\n",
       "  width: 50%;\n",
       "}\n",
       "\n",
       ".sk-global div.sk-parallel-item:only-child::after {\n",
       "  width: 0;\n",
       "}\n",
       "\n",
       "/* Serial-specific style estimator block */\n",
       "\n",
       ".sk-global 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-global 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-global 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: center;\n",
       "  justify-content: center;\n",
       "  gap: 0.5em;\n",
       "}\n",
       "\n",
       ".sk-global 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-global 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-global label.sk-toggleable__label-arrow:hover:before {\n",
       "  color: var(--sklearn-color-text);\n",
       "}\n",
       "\n",
       "/* Toggleable content - dropdown */\n",
       "\n",
       ".sk-global 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-global div.sk-toggleable__content.fitted {\n",
       "  /* fitted */\n",
       "  background-color: var(--sklearn-color-fitted-level-0);\n",
       "}\n",
       "\n",
       ".sk-global 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-global div.sk-toggleable__content.fitted pre {\n",
       "  /* unfitted */\n",
       "  background-color: var(--sklearn-color-fitted-level-0);\n",
       "}\n",
       "\n",
       ".sk-global 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-global input.sk-toggleable__control:checked~label.sk-toggleable__label-arrow:before {\n",
       "  content: \"▾\";\n",
       "}\n",
       "\n",
       "/* Pipeline/ColumnTransformer-specific style */\n",
       "\n",
       ".sk-global 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-global 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-global 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-global 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-global div.sk-label label.sk-toggleable__label,\n",
       ".sk-global 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-global 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-global 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-global div.sk-label label {\n",
       "  font-family: monospace;\n",
       "  font-weight: bold;\n",
       "  line-height: 1.2em;\n",
       "}\n",
       "\n",
       ".sk-global div.sk-label-container {\n",
       "  text-align: center;\n",
       "}\n",
       "\n",
       "/* Estimator-specific */\n",
       ".sk-global 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-global div.sk-estimator.fitted {\n",
       "  /* fitted */\n",
       "  background-color: var(--sklearn-color-fitted-level-0);\n",
       "}\n",
       "\n",
       "/* on hover */\n",
       ".sk-global div.sk-estimator:hover {\n",
       "  /* unfitted */\n",
       "  background-color: var(--sklearn-color-unfitted-level-2);\n",
       "}\n",
       "\n",
       ".sk-global 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-unfitted-level-0);\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-3) 1pt solid;\n",
       "  color: var(--sklearn-color-unfitted-level-3);\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",
       "  background-color: var(--sklearn-color-fitted-level-0);\n",
       "  border: var(--sklearn-color-fitted-level-3) 1pt solid;\n",
       "  color: var(--sklearn-color-fitted-level-3);\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",
       "  border: var(--sklearn-color-fitted-level-0) 1pt solid;\n",
       "  color: var(--sklearn-color-unfitted-level-0);\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",
       "  border: var(--sklearn-color-fitted-level-0) 1pt solid;\n",
       "  color: var(--sklearn-color-fitted-level-0);\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-global 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-unfitted-level-0);\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-global a.estimator_doc_link.fitted {\n",
       "  /* fitted */\n",
       "  background-color: var(--sklearn-color-fitted-level-0);\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-global 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-global a.estimator_doc_link.fitted:hover {\n",
       "  /* fitted */\n",
       "  background-color: var(--sklearn-color-fitted-level-3);\n",
       "}\n",
       "\n",
       ".sk-top-container.sk-global {\n",
       "  /* pydata-sphinx-theme hides overflow, so scrolling is disabled.\n",
       "   We need to set it to !important and add tabindex=\"0\" in the HTML\n",
       "   to allow keyboard-only users to navigate the display. */\n",
       "  overflow-x: scroll !important;\n",
       "  max-width: 100%;\n",
       "}\n",
       "\n",
       ".estimator-table {\n",
       "    font-family: monospace;\n",
       "}\n",
       "\n",
       ".estimator-table summary {\n",
       "    padding: .5rem;\n",
       "    cursor: pointer;\n",
       "}\n",
       "\n",
       ".estimator-table summary::marker {\n",
       "    font-size: 0.7rem;\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",
       "    margin-top: 0;\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 td {\n",
       "    background-color: #e0e0e0;\n",
       "}\n",
       "\n",
       ".estimator-table table :is(td, th) {\n",
       "    border: 1px solid rgba(106, 105, 104, 0.232);\n",
       "}\n",
       "\n",
       "/*\n",
       "    `table td`is set in notebook with right text-align.\n",
       "    We need to overwrite it.\n",
       "*/\n",
       ".estimator-table table td.param {\n",
       "    text-align: left;\n",
       "    position: relative;\n",
       "    padding: 0;\n",
       "}\n",
       "\n",
       ".user-set td {\n",
       "    color:rgb(255, 94, 0);\n",
       "    text-align: left !important;\n",
       "}\n",
       "\n",
       ".user-set td.value {\n",
       "    color:rgb(255, 94, 0);\n",
       "    background-color: transparent;\n",
       "}\n",
       "\n",
       ".default td, .estimator-table th {\n",
       "    color: black;\n",
       "    text-align: left !important;\n",
       "}\n",
       "\n",
       ".user-set td i,\n",
       ".default td i {\n",
       "    color: black;\n",
       "}\n",
       "\n",
       "td.fitted-att-type {\n",
       "    white-space: preserve nowrap;\n",
       "}\n",
       "\n",
       "/*\n",
       "    Styles for parameter documentation links\n",
       "    We need styling for visited so jupyter doesn't overwrite it\n",
       "*/\n",
       "a.param-doc-link,\n",
       "a.param-doc-link:link,\n",
       "a.param-doc-link:visited {\n",
       "    text-decoration: underline dashed;\n",
       "    text-underline-offset: .3em;\n",
       "    color: inherit;\n",
       "    display: block;\n",
       "    padding: .5em;\n",
       "}\n",
       "\n",
       "@supports(anchor-name: --doc-link) {\n",
       "    a.param-doc-link,\n",
       "    a.param-doc-link:link,\n",
       "    a.param-doc-link:visited {\n",
       "    anchor-name: --doc-link;\n",
       "    }\n",
       "}\n",
       "\n",
       "/* \"hack\" to make the entire area of the cell containing the link clickable */\n",
       "a.param-doc-link::before {\n",
       "    position: absolute;\n",
       "    content: \"\";\n",
       "    inset: 0;\n",
       "}\n",
       "\n",
       ".param-doc-description {\n",
       "    display: none;\n",
       "    position: absolute;\n",
       "    z-index: 9999;\n",
       "    left: 0;\n",
       "    padding: .5ex;\n",
       "    margin-left: 1.5em;\n",
       "    color: var(--sklearn-color-text);\n",
       "    box-shadow: .3em .3em .4em #999;\n",
       "    width: max-content;\n",
       "    text-align: left;\n",
       "    max-height: 10em;\n",
       "    overflow-y: auto;\n",
       "\n",
       "    /* unfitted */\n",
       "    background: var(--sklearn-color-unfitted-level-0);\n",
       "    border: thin solid var(--sklearn-color-unfitted-level-3);\n",
       "}\n",
       "\n",
       "@supports(position-area: center right) {\n",
       "    .param-doc-description {\n",
       "    position-area: center right;\n",
       "    position: fixed;\n",
       "    margin-left: 0;\n",
       "    }\n",
       "}\n",
       "\n",
       "/* Fitted state for parameter tooltips */\n",
       ".fitted .param-doc-description {\n",
       "    /* fitted */\n",
       "    background: var(--sklearn-color-fitted-level-0);\n",
       "    border: thin solid var(--sklearn-color-fitted-level-3);\n",
       "}\n",
       "\n",
       ".param-doc-link:hover .param-doc-description {\n",
       "    display: block;\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",
       "    border: none;\n",
       "    padding: 0;\n",
       "    background-color: transparent;\n",
       "}\n",
       "\n",
       ".copy-paste-icon:focus-visible {\n",
       "    outline: 1px solid currentColor;\n",
       "    outline-offset: 1px;\n",
       "}\n",
       "\n",
       ".features {\n",
       "  font-family: monospace;\n",
       "  cursor: pointer;\n",
       "  background-color: var(--sklearn-color-unfitted-level-0);\n",
       "  border: 1px dotted var(--sklearn-color-border-box);\n",
       "  border-radius: .20em;\n",
       "  margin-bottom: 0.5em;\n",
       "  font-size: inherit; /* Needed for jupyter */\n",
       "}\n",
       "\n",
       ".features.fitted {\n",
       "  background-color: var(--sklearn-color-fitted-level-0);\n",
       "}\n",
       "\n",
       ".features summary {\n",
       "  cursor: pointer;\n",
       "  display: flex;\n",
       "  margin-bottom: 0;\n",
       "  text-align: center;\n",
       "  align-items: center;\n",
       "  justify-content: center;\n",
       "  gap: 0.5em;\n",
       "  padding: .25em;\n",
       "}\n",
       "\n",
       ".features details[open] > summary {\n",
       "  color: var(--sklearn-color-text);\n",
       "  background-color: var(--sklearn-color-unfitted-level-2);\n",
       "  border-radius: .20em 0 0 0;\n",
       "}\n",
       "\n",
       ".features.fitted details[open] > summary {\n",
       "  background-color: var(--sklearn-color-fitted-level-2);\n",
       "  border-radius: .20em 0 0 0;\n",
       "}\n",
       "\n",
       ".features details > summary .arrow::before {\n",
       "  content: \"▸\";\n",
       "  color: grey;\n",
       "}\n",
       "\n",
       ".features details[open] > summary .arrow::before {\n",
       "  content: \"▾\";\n",
       "}\n",
       "\n",
       ".features details:hover > summary {\n",
       "  margin: 0;\n",
       "  background-color: var(--sklearn-color-unfitted-level-2);\n",
       "}\n",
       "\n",
       ".features.fitted details:hover > summary {\n",
       "  margin: 0;\n",
       "  background-color: var(--sklearn-color-fitted-level-2);\n",
       "}\n",
       "\n",
       ".features .features-container {\n",
       "  max-height: 10em;\n",
       "  overflow: auto;\n",
       "  scrollbar-width: thin;\n",
       "  padding: .25em 0.1rem;\n",
       "  background-color: var(--sklearn-color-unfitted-level-0);\n",
       "  border-radius: 0 0 .5em .5em;\n",
       "}\n",
       "\n",
       ".features.fitted .features-container {\n",
       "  background-color: var(--sklearn-color-fitted-level-0);\n",
       "}\n",
       "\n",
       ".features .image-container {\n",
       "  block-size: 1em;\n",
       "  inline-size: 1em;\n",
       "  padding: 0;\n",
       "  margin: 0%;\n",
       "  display: flex;\n",
       "  justify-content: center;\n",
       "  align-items: center;\n",
       "}\n",
       "\n",
       ".features .copy-paste-icon {\n",
       "  background-size: 1em 1em;\n",
       "  width: 1em;\n",
       "  height: 1em;\n",
       "  filter: grayscale(100%) opacity(60%);\n",
       "}\n",
       "\n",
       ".features .features-container table {\n",
       "  width: 100%;\n",
       "  margin: 0.01em;\n",
       "}\n",
       "\n",
       ".features .features-container table tr:nth-child(odd) {\n",
       "  background-color: #fff;\n",
       "}\n",
       "\n",
       ".features .features-container table tr:nth-child(even) {\n",
       "  background-color: #f6f6f6;\n",
       "}\n",
       "\n",
       ".features .features-container table tr:hover {\n",
       "  background-color: #e0e0e0;\n",
       "}\n",
       "\n",
       ".features .features-container table {\n",
       "  table-layout: inherit;\n",
       "}\n",
       "\n",
       ".features .features-container table td {\n",
       "  text-align: left;\n",
       "  padding: 0 0.5em;\n",
       "  border: 1px solid rgba(106, 105, 104, 0.232);\n",
       "  white-space: nowrap;\n",
       "  color: var(--sklearn-color-text);\n",
       "}\n",
       "\n",
       ".total_features {\n",
       "  display: flex;\n",
       "  justify-content: center;\n",
       "  margin-top: 0.5em;\n",
       "}\n",
       "</style><body><div id=\"sk-container-id-1\" tabindex=\"0\" class=\"sk-top-container sk-global\"><div class=\"sk-text-repr-fallback\"><pre>KNeighborsClassifier()</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 sk-global\" id=\"sk-estimator-id-1\" type=\"checkbox\" checked><label for=\"sk-estimator-id-1\" class=\"sk-toggleable__label fitted sk-toggleable__label-arrow\"><div><div>KNeighborsClassifier</div></div><div><a class=\"sk-estimator-doc-link fitted\" rel=\"noreferrer\" target=\"_blank\" href=\"https://scikit-learn.org/1.9/modules/generated/sklearn.neighbors.KNeighborsClassifier.html\">?<span>Documentation for KNeighborsClassifier</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=\"default\">\n",
       "            <td><button type=\"button\" class=\"copy-paste-icon\"\n",
       "                 aria-label=\"Copy n_neighbors to clipboard\"\n",
       "                 onclick=\"copyToClipboard('n_neighbors',\n",
       "                          this.parentElement.nextElementSibling)\"\n",
       "            ></button></td>\n",
       "            <td class=\"param\">\n",
       "        <a class=\"param-doc-link\"\n",
       "            style=\"anchor-name: --doc-link-n_neighbors;\"\n",
       "            rel=\"noreferrer\" target=\"_blank\" href=\"https://scikit-learn.org/1.9/modules/generated/sklearn.neighbors.KNeighborsClassifier.html#:~:text=n_neighbors,-int%2C%20default%3D5\">\n",
       "            n_neighbors\n",
       "            <span class=\"param-doc-description\"\n",
       "            style=\"position-anchor: --doc-link-n_neighbors;\">\n",
       "            n_neighbors: int, default=5<br><br>Number of neighbors to use by default for :meth:`kneighbors` queries.</span>\n",
       "        </a>\n",
       "    </td>\n",
       "            <td class=\"value\">5</td>\n",
       "        </tr>\n",
       "    \n",
       "\n",
       "        <tr class=\"default\">\n",
       "            <td><button type=\"button\" class=\"copy-paste-icon\"\n",
       "                 aria-label=\"Copy weights to clipboard\"\n",
       "                 onclick=\"copyToClipboard('weights',\n",
       "                          this.parentElement.nextElementSibling)\"\n",
       "            ></button></td>\n",
       "            <td class=\"param\">\n",
       "        <a class=\"param-doc-link\"\n",
       "            style=\"anchor-name: --doc-link-weights;\"\n",
       "            rel=\"noreferrer\" target=\"_blank\" href=\"https://scikit-learn.org/1.9/modules/generated/sklearn.neighbors.KNeighborsClassifier.html#:~:text=weights,-%7B%27uniform%27%2C%20%27distance%27%7D%2C%20callable%20or%20None%2C%20default%3D%27uniform%27\">\n",
       "            weights\n",
       "            <span class=\"param-doc-description\"\n",
       "            style=\"position-anchor: --doc-link-weights;\">\n",
       "            weights: {&#x27;uniform&#x27;, &#x27;distance&#x27;}, callable or None, default=&#x27;uniform&#x27;<br><br>Weight function used in prediction.  Possible values:<br><br>- &#x27;uniform&#x27; : uniform weights.  All points in each neighborhood<br>  are weighted equally.<br>- &#x27;distance&#x27; : weight points by the inverse of their distance.<br>  in this case, closer neighbors of a query point will have a<br>  greater influence than neighbors which are further away.<br>- [callable] : a user-defined function which accepts an<br>  array of distances, and returns an array of the same shape<br>  containing the weights.<br><br>Refer to the example entitled<br>:ref:`sphx_glr_auto_examples_neighbors_plot_classification.py`<br>showing the impact of the `weights` parameter on the decision<br>boundary.</span>\n",
       "        </a>\n",
       "    </td>\n",
       "            <td class=\"value\">&#x27;uniform&#x27;</td>\n",
       "        </tr>\n",
       "    \n",
       "\n",
       "        <tr class=\"default\">\n",
       "            <td><button type=\"button\" class=\"copy-paste-icon\"\n",
       "                 aria-label=\"Copy algorithm to clipboard\"\n",
       "                 onclick=\"copyToClipboard('algorithm',\n",
       "                          this.parentElement.nextElementSibling)\"\n",
       "            ></button></td>\n",
       "            <td class=\"param\">\n",
       "        <a class=\"param-doc-link\"\n",
       "            style=\"anchor-name: --doc-link-algorithm;\"\n",
       "            rel=\"noreferrer\" target=\"_blank\" href=\"https://scikit-learn.org/1.9/modules/generated/sklearn.neighbors.KNeighborsClassifier.html#:~:text=algorithm,-%7B%27auto%27%2C%20%27ball_tree%27%2C%20%27kd_tree%27%2C%20%27brute%27%7D%2C%20default%3D%27auto%27\">\n",
       "            algorithm\n",
       "            <span class=\"param-doc-description\"\n",
       "            style=\"position-anchor: --doc-link-algorithm;\">\n",
       "            algorithm: {&#x27;auto&#x27;, &#x27;ball_tree&#x27;, &#x27;kd_tree&#x27;, &#x27;brute&#x27;}, default=&#x27;auto&#x27;<br><br>Algorithm used to compute the nearest neighbors:<br><br>- &#x27;ball_tree&#x27; will use :class:`BallTree`<br>- &#x27;kd_tree&#x27; will use :class:`KDTree`<br>- &#x27;brute&#x27; will use a brute-force search.<br>- &#x27;auto&#x27; will attempt to decide the most appropriate algorithm<br>  based on the values passed to :meth:`fit` method.<br><br>Note: fitting on sparse input will override the setting of<br>this parameter, using brute force.</span>\n",
       "        </a>\n",
       "    </td>\n",
       "            <td class=\"value\">&#x27;auto&#x27;</td>\n",
       "        </tr>\n",
       "    \n",
       "\n",
       "        <tr class=\"default\">\n",
       "            <td><button type=\"button\" class=\"copy-paste-icon\"\n",
       "                 aria-label=\"Copy leaf_size to clipboard\"\n",
       "                 onclick=\"copyToClipboard('leaf_size',\n",
       "                          this.parentElement.nextElementSibling)\"\n",
       "            ></button></td>\n",
       "            <td class=\"param\">\n",
       "        <a class=\"param-doc-link\"\n",
       "            style=\"anchor-name: --doc-link-leaf_size;\"\n",
       "            rel=\"noreferrer\" target=\"_blank\" href=\"https://scikit-learn.org/1.9/modules/generated/sklearn.neighbors.KNeighborsClassifier.html#:~:text=leaf_size,-int%2C%20default%3D30\">\n",
       "            leaf_size\n",
       "            <span class=\"param-doc-description\"\n",
       "            style=\"position-anchor: --doc-link-leaf_size;\">\n",
       "            leaf_size: int, default=30<br><br>Leaf size passed to BallTree or KDTree.  This can affect the<br>speed of the construction and query, as well as the memory<br>required to store the tree.  The optimal value depends on the<br>nature of the problem.</span>\n",
       "        </a>\n",
       "    </td>\n",
       "            <td class=\"value\">30</td>\n",
       "        </tr>\n",
       "    \n",
       "\n",
       "        <tr class=\"default\">\n",
       "            <td><button type=\"button\" class=\"copy-paste-icon\"\n",
       "                 aria-label=\"Copy p to clipboard\"\n",
       "                 onclick=\"copyToClipboard('p',\n",
       "                          this.parentElement.nextElementSibling)\"\n",
       "            ></button></td>\n",
       "            <td class=\"param\">\n",
       "        <a class=\"param-doc-link\"\n",
       "            style=\"anchor-name: --doc-link-p;\"\n",
       "            rel=\"noreferrer\" target=\"_blank\" href=\"https://scikit-learn.org/1.9/modules/generated/sklearn.neighbors.KNeighborsClassifier.html#:~:text=p,-float%2C%20default%3D2\">\n",
       "            p\n",
       "            <span class=\"param-doc-description\"\n",
       "            style=\"position-anchor: --doc-link-p;\">\n",
       "            p: float, default=2<br><br>Power parameter for the Minkowski metric. When p = 1, this is equivalent<br>to using manhattan_distance (l1), and euclidean_distance (l2) for p = 2.<br>For arbitrary p, minkowski_distance (l_p) is used. This parameter is expected<br>to be positive.</span>\n",
       "        </a>\n",
       "    </td>\n",
       "            <td class=\"value\">2</td>\n",
       "        </tr>\n",
       "    \n",
       "\n",
       "        <tr class=\"default\">\n",
       "            <td><button type=\"button\" class=\"copy-paste-icon\"\n",
       "                 aria-label=\"Copy metric to clipboard\"\n",
       "                 onclick=\"copyToClipboard('metric',\n",
       "                          this.parentElement.nextElementSibling)\"\n",
       "            ></button></td>\n",
       "            <td class=\"param\">\n",
       "        <a class=\"param-doc-link\"\n",
       "            style=\"anchor-name: --doc-link-metric;\"\n",
       "            rel=\"noreferrer\" target=\"_blank\" href=\"https://scikit-learn.org/1.9/modules/generated/sklearn.neighbors.KNeighborsClassifier.html#:~:text=metric,-str%20or%20callable%2C%20default%3D%27minkowski%27\">\n",
       "            metric\n",
       "            <span class=\"param-doc-description\"\n",
       "            style=\"position-anchor: --doc-link-metric;\">\n",
       "            metric: str or callable, default=&#x27;minkowski&#x27;<br><br>Metric to use for distance computation. Default is &quot;minkowski&quot;, which<br>results in the standard Euclidean distance when p = 2. See the<br>documentation of `scipy.spatial.distance<br>&lt;https://docs.scipy.org/doc/scipy/reference/spatial.distance.html&gt;`_ and<br>the metrics listed in<br>:class:`~sklearn.metrics.pairwise.distance_metrics` for valid metric<br>values.<br><br>If metric is &quot;precomputed&quot;, X is assumed to be a distance matrix and<br>must be square during fit. X may be a :term:`sparse graph`, in which<br>case only &quot;nonzero&quot; elements may be considered neighbors.<br><br>If metric is a callable function, it takes two arrays representing 1D<br>vectors as inputs and must return one value indicating the distance<br>between those vectors. This works for Scipy&#x27;s metrics, but is less<br>efficient than passing the metric name as a string.</span>\n",
       "        </a>\n",
       "    </td>\n",
       "            <td class=\"value\">&#x27;minkowski&#x27;</td>\n",
       "        </tr>\n",
       "    \n",
       "\n",
       "        <tr class=\"default\">\n",
       "            <td><button type=\"button\" class=\"copy-paste-icon\"\n",
       "                 aria-label=\"Copy metric_params to clipboard\"\n",
       "                 onclick=\"copyToClipboard('metric_params',\n",
       "                          this.parentElement.nextElementSibling)\"\n",
       "            ></button></td>\n",
       "            <td class=\"param\">\n",
       "        <a class=\"param-doc-link\"\n",
       "            style=\"anchor-name: --doc-link-metric_params;\"\n",
       "            rel=\"noreferrer\" target=\"_blank\" href=\"https://scikit-learn.org/1.9/modules/generated/sklearn.neighbors.KNeighborsClassifier.html#:~:text=metric_params,-dict%2C%20default%3DNone\">\n",
       "            metric_params\n",
       "            <span class=\"param-doc-description\"\n",
       "            style=\"position-anchor: --doc-link-metric_params;\">\n",
       "            metric_params: dict, default=None<br><br>Additional keyword arguments for the metric function.</span>\n",
       "        </a>\n",
       "    </td>\n",
       "            <td class=\"value\">None</td>\n",
       "        </tr>\n",
       "    \n",
       "\n",
       "        <tr class=\"default\">\n",
       "            <td><button type=\"button\" class=\"copy-paste-icon\"\n",
       "                 aria-label=\"Copy n_jobs to clipboard\"\n",
       "                 onclick=\"copyToClipboard('n_jobs',\n",
       "                          this.parentElement.nextElementSibling)\"\n",
       "            ></button></td>\n",
       "            <td class=\"param\">\n",
       "        <a class=\"param-doc-link\"\n",
       "            style=\"anchor-name: --doc-link-n_jobs;\"\n",
       "            rel=\"noreferrer\" target=\"_blank\" href=\"https://scikit-learn.org/1.9/modules/generated/sklearn.neighbors.KNeighborsClassifier.html#:~:text=n_jobs,-int%2C%20default%3DNone\">\n",
       "            n_jobs\n",
       "            <span class=\"param-doc-description\"\n",
       "            style=\"position-anchor: --doc-link-n_jobs;\">\n",
       "            n_jobs: int, default=None<br><br>The number of parallel jobs to run for neighbors search.<br>``None`` means 1 unless in a :obj:`joblib.parallel_backend` context.<br>``-1`` means using all processors. See :term:`Glossary &lt;n_jobs&gt;`<br>for more details.<br>Doesn&#x27;t affect :meth:`fit` method.</span>\n",
       "        </a>\n",
       "    </td>\n",
       "            <td class=\"value\">None</td>\n",
       "        </tr>\n",
       "    \n",
       "                  </tbody>\n",
       "                </table>\n",
       "            </details>\n",
       "        </div>\n",
       "    \n",
       "        <div class=\"estimator-table\">\n",
       "            <details>\n",
       "                <summary>Fitted attributes</summary>\n",
       "                <table class=\"parameters-table\">\n",
       "                    <tbody>\n",
       "                        <tr>\n",
       "                        <th>Name</th>\n",
       "                        <th>Type</th>\n",
       "                        <th>Value</th>\n",
       "                        </tr>\n",
       "                        \n",
       "       <tr class=\"default\">\n",
       "           <td class=\"param\">\n",
       "        <a class=\"param-doc-link\"\n",
       "            style=\"anchor-name: --doc-link-classes_;\"\n",
       "            rel=\"noreferrer\" target=\"_blank\" href=\"https://scikit-learn.org/1.9/modules/generated/sklearn.neighbors.KNeighborsClassifier.html#:~:text=classes_,-array%20of%20shape%20%28n_classes%2C%29\">\n",
       "            classes_\n",
       "            <span class=\"param-doc-description\"\n",
       "            style=\"position-anchor: --doc-link-classes_;\">\n",
       "            classes_: array of shape (n_classes,)<br><br>Class labels known to the classifier</span>\n",
       "        </a>\n",
       "    </td>\n",
       "           <td class=\"fitted-att-type\">ndarray[int64](2,)</td>\n",
       "           <td>[0,1]</td>\n",
       "\n",
       "\n",
       "       </tr>\n",
       "    \n",
       "\n",
       "       <tr class=\"default\">\n",
       "           <td class=\"param\">\n",
       "        <a class=\"param-doc-link\"\n",
       "            style=\"anchor-name: --doc-link-effective_metric_;\"\n",
       "            rel=\"noreferrer\" target=\"_blank\" href=\"https://scikit-learn.org/1.9/modules/generated/sklearn.neighbors.KNeighborsClassifier.html#:~:text=effective_metric_,-str%20or%20callble\">\n",
       "            effective_metric_\n",
       "            <span class=\"param-doc-description\"\n",
       "            style=\"position-anchor: --doc-link-effective_metric_;\">\n",
       "            effective_metric_: str or callble<br><br>The distance metric used. It will be same as the `metric` parameter<br>or a synonym of it, e.g. &#x27;euclidean&#x27; if the `metric` parameter set to<br>&#x27;minkowski&#x27; and `p` parameter set to 2.</span>\n",
       "        </a>\n",
       "    </td>\n",
       "           <td class=\"fitted-att-type\">str</td>\n",
       "           <td>&#x27;eu...an&#x27;</td>\n",
       "\n",
       "\n",
       "       </tr>\n",
       "    \n",
       "\n",
       "       <tr class=\"default\">\n",
       "           <td class=\"param\">\n",
       "        <a class=\"param-doc-link\"\n",
       "            style=\"anchor-name: --doc-link-effective_metric_params_;\"\n",
       "            rel=\"noreferrer\" target=\"_blank\" href=\"https://scikit-learn.org/1.9/modules/generated/sklearn.neighbors.KNeighborsClassifier.html#:~:text=effective_metric_params_,-dict\">\n",
       "            effective_metric_params_\n",
       "            <span class=\"param-doc-description\"\n",
       "            style=\"position-anchor: --doc-link-effective_metric_params_;\">\n",
       "            effective_metric_params_: dict<br><br>Additional keyword arguments for the metric function. For most metrics<br>will be same with `metric_params` parameter, but may also contain the<br>`p` parameter value if the `effective_metric_` attribute is set to<br>&#x27;minkowski&#x27;.</span>\n",
       "        </a>\n",
       "    </td>\n",
       "           <td class=\"fitted-att-type\">dict</td>\n",
       "           <td>{}</td>\n",
       "\n",
       "\n",
       "       </tr>\n",
       "    \n",
       "\n",
       "       <tr class=\"default\">\n",
       "           <td class=\"param\">\n",
       "        <a class=\"param-doc-link\"\n",
       "            style=\"anchor-name: --doc-link-n_features_in_;\"\n",
       "            rel=\"noreferrer\" target=\"_blank\" href=\"https://scikit-learn.org/1.9/modules/generated/sklearn.neighbors.KNeighborsClassifier.html#:~:text=n_features_in_,-int\">\n",
       "            n_features_in_\n",
       "            <span class=\"param-doc-description\"\n",
       "            style=\"position-anchor: --doc-link-n_features_in_;\">\n",
       "            n_features_in_: int<br><br>Number of features seen during :term:`fit`.<br><br>.. versionadded:: 0.24</span>\n",
       "        </a>\n",
       "    </td>\n",
       "           <td class=\"fitted-att-type\">int</td>\n",
       "           <td>3</td>\n",
       "\n",
       "\n",
       "       </tr>\n",
       "    \n",
       "\n",
       "       <tr class=\"default\">\n",
       "           <td class=\"param\">\n",
       "        <a class=\"param-doc-link\"\n",
       "            style=\"anchor-name: --doc-link-n_samples_fit_;\"\n",
       "            rel=\"noreferrer\" target=\"_blank\" href=\"https://scikit-learn.org/1.9/modules/generated/sklearn.neighbors.KNeighborsClassifier.html#:~:text=n_samples_fit_,-int\">\n",
       "            n_samples_fit_\n",
       "            <span class=\"param-doc-description\"\n",
       "            style=\"position-anchor: --doc-link-n_samples_fit_;\">\n",
       "            n_samples_fit_: int<br><br>Number of samples in the fitted data.</span>\n",
       "        </a>\n",
       "    </td>\n",
       "           <td class=\"fitted-att-type\">int</td>\n",
       "           <td>8631</td>\n",
       "\n",
       "\n",
       "       </tr>\n",
       "    \n",
       "\n",
       "       <tr class=\"default\">\n",
       "           <td class=\"param\">\n",
       "        <a class=\"param-doc-link\"\n",
       "            style=\"anchor-name: --doc-link-outputs_2d_;\"\n",
       "            rel=\"noreferrer\" target=\"_blank\" href=\"https://scikit-learn.org/1.9/modules/generated/sklearn.neighbors.KNeighborsClassifier.html#:~:text=outputs_2d_,-bool\">\n",
       "            outputs_2d_\n",
       "            <span class=\"param-doc-description\"\n",
       "            style=\"position-anchor: --doc-link-outputs_2d_;\">\n",
       "            outputs_2d_: bool<br><br>False when `y`&#x27;s shape is (n_samples, ) or (n_samples, 1) during fit<br>otherwise True.</span>\n",
       "        </a>\n",
       "    </td>\n",
       "           <td class=\"fitted-att-type\">bool</td>\n",
       "           <td>False</td>\n",
       "\n",
       "\n",
       "       </tr>\n",
       "    \n",
       "                    </tbody>\n",
       "                </table>\n",
       "            </details>\n",
       "        </div>\n",
       "    </div></div></div></div></div><script>/*  Authors: The scikit-learn developers\n",
       " SPDX-License-Identifier: BSD-3-Clause\n",
       "*/\n",
       "\n",
       "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('.copy-paste-icon').forEach(function(element) {\n",
       "    const toggleableContent = element.closest('.sk-toggleable__content');\n",
       "    const paramPrefix = toggleableContent ? toggleableContent.dataset.paramPrefix : '';\n",
       "\n",
       "    const parent = element.parentElement;\n",
       "    if (!parent || !parent.nextElementSibling) {\n",
       "        console.warn('Expected copy-paste icon is missing from the DOM structure');\n",
       "        return;\n",
       "    }\n",
       "\n",
       "    const paramName = element.parentElement.nextElementSibling\n",
       "        .textContent.trim().split(' ')[0];\n",
       "    const fullParamName = paramPrefix ? `${paramPrefix}${paramName}` : paramName;\n",
       "\n",
       "    element.setAttribute('title', fullParamName);\n",
       "});\n",
       "\n",
       "/**\n",
       " * Copy the list of feature names formatted as a Python list.\n",
       " *\n",
       " * @param {HTMLElement} element - The copy button inside a `.features` block; its siblings\n",
       " *   contain a `details` element and a table containing feature named.\n",
       " * @returns {boolean} Always returns `false` so callers can prevent the default click behavior.\n",
       " */\n",
       "function copyFeatureNamesToClipboard(element) {\n",
       "    var detailsElem = element.closest('.features').querySelector('details');\n",
       "    var wasOpen = detailsElem.open;\n",
       "    detailsElem.open = true;\n",
       "    var content = element.closest('.features').querySelector('tbody')\n",
       "                  .innerText.trim();\n",
       "    if (!wasOpen) detailsElem.open = false;\n",
       "    const rows = content.split('\\n').map(row => `    \"${row}\"`);\n",
       "    const formattedText = `[\\n${rows.join(',\\n')},\\n]`;\n",
       "    const originalHTML = element.innerHTML.replace('✔', '');\n",
       "    const originalStyle = element.style;\n",
       "    const copyMark = document.createElement('span');\n",
       "    copyMark.innerHTML = '✔';\n",
       "    copyMark.style.color = 'blue';\n",
       "    copyMark.style.fontSize = '1em';\n",
       "\n",
       "    navigator.clipboard.writeText(formattedText)\n",
       "        .then(() => {\n",
       "            element.style.display = 'none';\n",
       "            element.parentElement.appendChild(copyMark);\n",
       "\n",
       "            setTimeout(() => {\n",
       "                copyMark.remove();\n",
       "                element.innerHTML = originalHTML;\n",
       "                element.style = originalStyle;\n",
       "            }, 1000);\n",
       "        })\n",
       "        .catch(err => {\n",
       "            console.error('Failed to copy:', err);\n",
       "            element.style.color = 'orange';\n",
       "            element.innerHTML = \"Failed!\";\n",
       "            setTimeout(() => {\n",
       "                element.innerHTML = originalHTML;\n",
       "                element.style = originalStyle;\n",
       "            }, 1000);\n",
       "        });\n",
       "    return false;\n",
       "}\n",
       "/**\n",
       " * Adapted from Skrub\n",
       " * https://github.com/skrub-data/skrub/blob/403466d1d5d4dc76a7ef569b3f8228db59a31dc3/skrub/_reporting/_data/templates/report.js#L789\n",
       " * @returns \"light\" or \"dark\"\n",
       " */\n",
       "function detectTheme(element) {\n",
       "    const body = document.querySelector('body');\n",
       "\n",
       "    // Check VSCode theme\n",
       "    const themeKindAttr = body.getAttribute('data-vscode-theme-kind');\n",
       "    const themeNameAttr = body.getAttribute('data-vscode-theme-name');\n",
       "\n",
       "    if (themeKindAttr && themeNameAttr) {\n",
       "        const themeKind = themeKindAttr.toLowerCase();\n",
       "        const themeName = themeNameAttr.toLowerCase();\n",
       "\n",
       "        if (themeKind.includes(\"dark\") || themeName.includes(\"dark\")) {\n",
       "            return \"dark\";\n",
       "        }\n",
       "        if (themeKind.includes(\"light\") || themeName.includes(\"light\")) {\n",
       "            return \"light\";\n",
       "        }\n",
       "    }\n",
       "\n",
       "    // Check Jupyter theme\n",
       "    if (body.getAttribute('data-jp-theme-light') === 'false') {\n",
       "        return 'dark';\n",
       "    } else if (body.getAttribute('data-jp-theme-light') === 'true') {\n",
       "        return 'light';\n",
       "    }\n",
       "\n",
       "    // Guess based on a parent element's color\n",
       "    const color = window.getComputedStyle(element.parentNode, null).getPropertyValue('color');\n",
       "    const match = color.match(/^rgb\\s*\\(\\s*(\\d+)\\s*,\\s*(\\d+)\\s*,\\s*(\\d+)\\s*\\)\\s*$/i);\n",
       "    if (match) {\n",
       "        const [r, g, b] = [\n",
       "            parseFloat(match[1]),\n",
       "            parseFloat(match[2]),\n",
       "            parseFloat(match[3])\n",
       "        ];\n",
       "\n",
       "        // https://en.wikipedia.org/wiki/HSL_and_HSV#Lightness\n",
       "        const luma = 0.299 * r + 0.587 * g + 0.114 * b;\n",
       "\n",
       "        if (luma > 180) {\n",
       "            // If the text is very bright we have a dark theme\n",
       "            return 'dark';\n",
       "        }\n",
       "        if (luma < 75) {\n",
       "            // If the text is very dark we have a light theme\n",
       "            return 'light';\n",
       "        }\n",
       "        // Otherwise fall back to the next heuristic.\n",
       "    }\n",
       "\n",
       "    // Fallback to system preference\n",
       "    return window.matchMedia('(prefers-color-scheme: dark)').matches ? 'dark' : 'light';\n",
       "}\n",
       "\n",
       "\n",
       "function forceTheme(elementId) {\n",
       "    const estimatorElement = document.querySelector(`#${elementId}`);\n",
       "    if (estimatorElement === null) {\n",
       "        console.error(`Element with id ${elementId} not found.`);\n",
       "    } else {\n",
       "        const theme = detectTheme(estimatorElement);\n",
       "        estimatorElement.classList.add(theme);\n",
       "    }\n",
       "}\n",
       "\n",
       "forceTheme('sk-container-id-1');</script></body>"
      ],
      "text/plain": [
       "KNeighborsClassifier()"
      ]
     },
     "execution_count": 17,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "knn = KNeighborsClassifier(n_neighbors=5)\n",
    "knn.fit(X_train_scaled, y_train)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "c032",
   "metadata": {},
   "source": [
    "To classify the new session from the previous subsection, scale it with the same scaler and call `predict`."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "id": "c033",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2026-11-17T23:43:42.569831Z",
     "iopub.status.busy": "2026-11-17T23:43:42.569760Z",
     "iopub.status.idle": "2026-11-17T23:43:42.573225Z",
     "shell.execute_reply": "2026-11-17T23:43:42.572835Z"
    },
    "tags": []
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([1])"
      ]
     },
     "execution_count": 18,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "new_scaled = scaler.transform(new_session)\n",
    "knn.predict(new_scaled)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "c034",
   "metadata": {},
   "source": [
    "The prediction is 1: this session is likely to end in a purchase. The `kneighbors` method shows the evidence behind the vote, the distances to the 5 nearest training sessions and their positions in the training set. Three of the five neighbors ended in a purchase, so the vote is 3 to 2. Looking up those sessions confirms that it is the same distance-and-vote procedure written by hand."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "id": "c035",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2026-11-17T23:43:42.574207Z",
     "iopub.status.busy": "2026-11-17T23:43:42.574146Z",
     "iopub.status.idle": "2026-11-17T23:43:42.577623Z",
     "shell.execute_reply": "2026-11-17T23:43:42.577353Z"
    },
    "tags": []
   },
   "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>page_value</th>\n",
       "      <th>exit_rate</th>\n",
       "      <th>product_pages</th>\n",
       "      <th>purchase</th>\n",
       "      <th>distance</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>5665</th>\n",
       "      <td>12.905876</td>\n",
       "      <td>0.018286</td>\n",
       "      <td>30</td>\n",
       "      <td>0</td>\n",
       "      <td>0.059</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4670</th>\n",
       "      <td>11.284275</td>\n",
       "      <td>0.021453</td>\n",
       "      <td>28</td>\n",
       "      <td>0</td>\n",
       "      <td>0.066</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>7428</th>\n",
       "      <td>12.587222</td>\n",
       "      <td>0.016667</td>\n",
       "      <td>28</td>\n",
       "      <td>1</td>\n",
       "      <td>0.088</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>10133</th>\n",
       "      <td>13.490319</td>\n",
       "      <td>0.019670</td>\n",
       "      <td>32</td>\n",
       "      <td>1</td>\n",
       "      <td>0.091</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>10013</th>\n",
       "      <td>10.388944</td>\n",
       "      <td>0.022857</td>\n",
       "      <td>30</td>\n",
       "      <td>1</td>\n",
       "      <td>0.103</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "       page_value  exit_rate  product_pages  purchase  distance\n",
       "5665    12.905876   0.018286             30         0     0.059\n",
       "4670    11.284275   0.021453             28         0     0.066\n",
       "7428    12.587222   0.016667             28         1     0.088\n",
       "10133   13.490319   0.019670             32         1     0.091\n",
       "10013   10.388944   0.022857             30         1     0.103"
      ]
     },
     "execution_count": 19,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "distances, positions = knn.kneighbors(new_scaled)\n",
    "\n",
    "neighbors = X_train.iloc[positions[0]].copy()\n",
    "neighbors['purchase'] = y_train.iloc[positions[0]].values\n",
    "neighbors['distance'] = distances[0].round(3)\n",
    "neighbors"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "c036",
   "metadata": {},
   "source": [
    "Now classify every test session at once and compare the predictions with the actual labels. Accuracy is the proportion of matches; `accuracy_score` computes it, and so does the classifier's own `score` method."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "id": "c037",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2026-11-17T23:43:42.578613Z",
     "iopub.status.busy": "2026-11-17T23:43:42.578559Z",
     "iopub.status.idle": "2026-11-17T23:43:42.586634Z",
     "shell.execute_reply": "2026-11-17T23:43:42.586389Z"
    },
    "tags": []
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "First ten predictions: [0 0 0 1 0 0 0 0 0 1]\n",
      "First ten actual:      [0 0 0 1 0 0 0 0 0 0]\n",
      "Test accuracy: 0.878\n"
     ]
    }
   ],
   "source": [
    "y_pred = knn.predict(X_test_scaled)\n",
    "\n",
    "print('First ten predictions:', y_pred[:10])\n",
    "print('First ten actual:     ', y_test.values[:10])\n",
    "print('Test accuracy:', round(accuracy_score(y_test, y_pred), 3))"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "c038",
   "metadata": {},
   "source": [
    "The 5-nearest neighbor classifier is right for 88% of the test sessions, a few points above the 85% of the always-\"no purchase\" rule.\n",
    "\n",
    "How much did scaling help? Fit the same classifier on the raw features and compare."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "id": "c039",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2026-11-17T23:43:42.587702Z",
     "iopub.status.busy": "2026-11-17T23:43:42.587642Z",
     "iopub.status.idle": "2026-11-17T23:43:42.606279Z",
     "shell.execute_reply": "2026-11-17T23:43:42.605890Z"
    },
    "tags": []
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Test accuracy without scaling: 0.876\n",
      "Test accuracy with scaling:    0.878\n"
     ]
    }
   ],
   "source": [
    "knn_raw = KNeighborsClassifier(n_neighbors=5)\n",
    "knn_raw.fit(X_train, y_train)\n",
    "\n",
    "print('Test accuracy without scaling:', round(knn_raw.score(X_test, y_test), 3))\n",
    "print('Test accuracy with scaling:   ', round(knn.score(X_test_scaled, y_test), 3))"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "c040",
   "metadata": {},
   "source": [
    "Here scaling barely changes the accuracy (0.876 without it, 0.878 with it). That is not because scaling is unimportant. Without scaling, the distance is decided almost entirely by the product page count and the page value, because the exit rate never differs by more than 0.2 and so adds almost nothing. Those two attributes happen to carry most of the signal in this data set, so the accuracy hardly moves. With other attributes, the unscaled classifier could ignore the most useful one, as the product-duration example in Section {doc}`../14-classification/1402-nearest-neighbors` showed, so scaling is part of the nearest neighbor method, not an optional extra."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 22,
   "id": "c041",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2026-11-17T23:43:42.607350Z",
     "iopub.status.busy": "2026-11-17T23:43:42.607289Z",
     "iopub.status.idle": "2026-11-17T23:43:42.608826Z",
     "shell.execute_reply": "2026-11-17T23:43:42.608473Z"
    },
    "tags": [
     "thebe-interactive"
    ]
   },
   "outputs": [],
   "source": [
    "### Exercise: Try k = 7\n",
    "#   1. Fit a KNeighborsClassifier with n_neighbors=7 on X_train_scaled and y_train.\n",
    "#   2. Predict the test set (X_test_scaled) and print the test accuracy rounded to 3 decimals.\n",
    "#   3. Predict new_session (use new_scaled) and print the predicted label.\n",
    "# Print exactly:\n",
    "# Test accuracy: 0.881\n",
    "# New session prediction: 0\n",
    "### Your code starts here.\n",
    "\n",
    "\n",
    "\n",
    "\n",
    "### Your code ends here."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 23,
   "id": "c042",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2026-11-17T23:43:42.609672Z",
     "iopub.status.busy": "2026-11-17T23:43:42.609611Z",
     "iopub.status.idle": "2026-11-17T23:43:42.619805Z",
     "shell.execute_reply": "2026-11-17T23:43:42.619510Z"
    },
    "tags": [
     "hide-input"
    ]
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Test accuracy: 0.881\n",
      "New session prediction: 0\n"
     ]
    }
   ],
   "source": [
    "### Solution\n",
    "ex_knn7 = KNeighborsClassifier(n_neighbors=7)\n",
    "ex_knn7.fit(X_train_scaled, y_train)\n",
    "\n",
    "print('Test accuracy:', round(accuracy_score(y_test, ex_knn7.predict(X_test_scaled)), 3))\n",
    "print('New session prediction:', ex_knn7.predict(new_scaled)[0])"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "c043",
   "metadata": {},
   "source": [
    "## Pipelines and Choosing k\n",
    "\n",
    "```{index} pipeline\n",
    "```\n",
    "\n",
    "```{index} make_pipeline\n",
    "```\n",
    "\n",
    "```{index} validation set\n",
    "```\n",
    "\n",
    "```{index} choosing k\n",
    "```\n",
    "\n",
    "```{index} hyperparameter\n",
    "```\n",
    "\n",
    "Keeping track of a separate scaler and classifier is easy to get wrong, for example by forgetting to scale a new session. A **pipeline** joins the steps into one object. When you call `fit` on the pipeline, it fits the scaler on the training data, transforms them, and fits the classifier; when you call `predict`, it transforms the new rows with the *training* statistics and then predicts. Scaling with training statistics only is built in."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 24,
   "id": "c044",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2026-11-17T23:43:42.620761Z",
     "iopub.status.busy": "2026-11-17T23:43:42.620695Z",
     "iopub.status.idle": "2026-11-17T23:43:42.631964Z",
     "shell.execute_reply": "2026-11-17T23:43:42.631662Z"
    },
    "tags": []
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Test accuracy: 0.878\n",
      "New session prediction: 1\n"
     ]
    }
   ],
   "source": [
    "model = make_pipeline(StandardScaler(), KNeighborsClassifier(n_neighbors=5))\n",
    "model.fit(X_train, y_train)\n",
    "\n",
    "print('Test accuracy:', round(model.score(X_test, y_test), 3))\n",
    "print('New session prediction:', model.predict(new_session)[0])"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "c045",
   "metadata": {},
   "source": [
    "The pipeline gives the same accuracy and prediction as the two separate steps, and it takes the raw features directly.\n",
    "\n",
    "**Choosing $k$.** The number of neighbors is a choice you make, not something `fit` learns from the data; such choices are called *hyperparameters*. A natural idea is to try several values of $k$ and keep the one with the best test accuracy. But then the test set has been used to build the classifier, and its accuracy is no longer an honest estimate for new sessions, the same problem as testing on the training set, only milder.\n",
    "\n",
    "The fix is the one from Section {doc}`../14-classification/1403-training-testing-accuracy`: a **validation set**. Split the training set once more, use one part to fit and the other part to compare values of $k$, and save the test set for a single final check. There you sliced the first part of the shuffled training set by hand; `train_test_split` does it in one call."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 25,
   "id": "c046",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2026-11-17T23:43:42.632938Z",
     "iopub.status.busy": "2026-11-17T23:43:42.632875Z",
     "iopub.status.idle": "2026-11-17T23:43:42.636265Z",
     "shell.execute_reply": "2026-11-17T23:43:42.635915Z"
    },
    "tags": []
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "6473 sessions for fitting and 2158 for validation\n"
     ]
    }
   ],
   "source": [
    "X_fit, X_val, y_fit, y_val = train_test_split(\n",
    "    X_train, y_train, test_size=0.25, random_state=14, stratify=y_train)\n",
    "\n",
    "print(len(X_fit), 'sessions for fitting and', len(X_val), 'for validation')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 26,
   "id": "c047",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2026-11-17T23:43:42.637098Z",
     "iopub.status.busy": "2026-11-17T23:43:42.637049Z",
     "iopub.status.idle": "2026-11-17T23:43:42.759868Z",
     "shell.execute_reply": "2026-11-17T23:43:42.759467Z"
    },
    "tags": []
   },
   "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>k</th>\n",
       "      <th>validation accuracy</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>1</td>\n",
       "      <td>0.856</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>3</td>\n",
       "      <td>0.886</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>5</td>\n",
       "      <td>0.896</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>7</td>\n",
       "      <td>0.897</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>9</td>\n",
       "      <td>0.897</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>11</td>\n",
       "      <td>0.899</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>6</th>\n",
       "      <td>13</td>\n",
       "      <td>0.897</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>7</th>\n",
       "      <td>15</td>\n",
       "      <td>0.897</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8</th>\n",
       "      <td>17</td>\n",
       "      <td>0.895</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9</th>\n",
       "      <td>19</td>\n",
       "      <td>0.896</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>10</th>\n",
       "      <td>21</td>\n",
       "      <td>0.896</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>11</th>\n",
       "      <td>23</td>\n",
       "      <td>0.892</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>12</th>\n",
       "      <td>25</td>\n",
       "      <td>0.895</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>13</th>\n",
       "      <td>27</td>\n",
       "      <td>0.893</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>14</th>\n",
       "      <td>29</td>\n",
       "      <td>0.892</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>15</th>\n",
       "      <td>31</td>\n",
       "      <td>0.896</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "     k  validation accuracy\n",
       "0    1                0.856\n",
       "1    3                0.886\n",
       "2    5                0.896\n",
       "3    7                0.897\n",
       "4    9                0.897\n",
       "5   11                0.899\n",
       "6   13                0.897\n",
       "7   15                0.897\n",
       "8   17                0.895\n",
       "9   19                0.896\n",
       "10  21                0.896\n",
       "11  23                0.892\n",
       "12  25                0.895\n",
       "13  27                0.893\n",
       "14  29                0.892\n",
       "15  31                0.896"
      ]
     },
     "execution_count": 26,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "k_values = np.arange(1, 32, 2)     # odd values of k avoid ties in a two-class vote\n",
    "val_accuracy = []\n",
    "\n",
    "for k in k_values:\n",
    "    candidate = make_pipeline(StandardScaler(), KNeighborsClassifier(n_neighbors=k))\n",
    "    candidate.fit(X_fit, y_fit)\n",
    "    val_accuracy.append(candidate.score(X_val, y_val))\n",
    "\n",
    "k_results = pd.DataFrame({'k': k_values, 'validation accuracy': np.round(val_accuracy, 3)})\n",
    "k_results"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 27,
   "id": "c048",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2026-11-17T23:43:42.761001Z",
     "iopub.status.busy": "2026-11-17T23:43:42.760935Z",
     "iopub.status.idle": "2026-11-17T23:43:42.810569Z",
     "shell.execute_reply": "2026-11-17T23:43:42.810288Z"
    },
    "tags": []
   },
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAmkAAAFlCAYAAACwW380AAAAOnRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjExLjIsIGh0dHBzOi8vbWF0cGxvdGxpYi5vcmcvgI3uAAAAAAlwSFlzAAAPYQAAD2EBqD+naQAAZmZJREFUeJztnQeUE2Xbhp/tvVKW3nsvUkWKKEUERQQVFLAg/2f9VKR9WAHBgl1EsCEoNlRAkCpILyIdpPelb2PZXv5zv2FCNpvsJtlk0+7rnJzJTmZnJm/eZO55qk9SUlK+EEIIIYQQl8LX2SdACCGEEEIKQ5FGCCGEEOKCUKQRQgghhLggFGmEEEIIIS4IRRohhBBCiAtCkUYIIYQQ4oJQpBFCCCGEuCAUaYQQQgghLghFGiGEEEKIC+IvbsTu3btlz5494u/vLzfddJPUrl3b6n2kp6fLhg0b5OzZsxIZGSk333yzlC9f3uHHJYQQQgjxOJGWkpIijzzyiKxcubLA+oceekjef/998fPzs2g/S5YskWeeeUYuX76sXwfh9eKLL8qYMWMcdlxCCCGEEI90d/7nP/9RQik6OloGDRok/fv3l5CQEJkzZ45MmjTJon3s3LlThg0bpgRao0aNZPDgwdKzZ0/x8fGRKVOmyKxZsxxyXFNkZGTIsWPH1JJw7EoLzjuOnTPgvOPYcd55sCUN4mrx4sXKJbl69WqpXLmyWr9r1y4lsqZPny5PP/20xMbGFrmfjz76SLKzs+WJJ56QyZMnK3Gm7adXr15KqEHEBQYG2vW45sjNzbXp/wjHriRw3nHsnAHnHceO885DLWm///67WkJcaUIJNG/eXO677z7JzMyUZcuWFbufHTt2qCVcm5pA0/YD0ZWQkCBr1661+3EJIYQQQjxSpCFgH3Tp0qXQa127dtUH9hcHrGgQZwEBAYVe06xnsJLZ+7iEEEIIIR7p7kQWJq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NVD7y7hWGv6GyxACDTFYcPeTwqBgLuJVYW2ztm8s8R5oSSPERUFBTsT1wJoGN6I9K9YTYg/gHsW8RPwlXNhwHcL1qJWPQZYnGp6TwiCW7tVXXy3UYJ4QQyjSCHFhUBIBFgkkD2j10whxFZ555hllTTMsgwEQ2zh+/Hh9UVdSGMTcIYZt8ODBNvX4Jd4BRRohhBCbgUse5StQxgNWX62Buanm54QQ66BII4QQQghxQWhjJYQQQghxQSjSCCGEEEJcEIo0QgghhBAXhCKNEEIIIcQFoUgjhBBCCHFBKNIIIYQQQlwQijRCCCGEEBeEIo0QQgghxAWhSCOEEEIIEdfj/wGfna73u12nQQAAAABJRU5ErkJggg==",
      "text/plain": [
       "<Figure size 600x350 with 1 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "fig, ax = plt.subplots(figsize=(6, 3.5))\n",
    "ax.plot(k_results['k'], k_results['validation accuracy'], marker='o', lw=2)\n",
    "ax.set_xlabel('k (number of neighbors)')\n",
    "ax.set_ylabel('Validation accuracy')\n",
    "plt.show()"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "c049",
   "metadata": {},
   "source": [
    "With $k = 1$ the classifier follows individual training sessions too closely (it *overfits*), and validation accuracy is lowest. Accuracy rises as $k$ grows and then levels off at about 0.90; very large $k$ would eventually blur the pattern, because distant sessions get a vote. Pick the $k$ with the highest validation accuracy, refit on the whole training set, and check the test set once. Section {doc}`../14-classification/1403-training-testing-accuracy` compared only $k$ = 1, 5, 15, and 51 on a different validation set and took 51. Once accuracy levels off, the differences among larger values of $k$ are small, so a different split or a different list of candidates can pick a different $k$ with about the same accuracy."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 28,
   "id": "c050",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2026-11-17T23:43:42.811676Z",
     "iopub.status.busy": "2026-11-17T23:43:42.811608Z",
     "iopub.status.idle": "2026-11-17T23:43:42.824319Z",
     "shell.execute_reply": "2026-11-17T23:43:42.823965Z"
    },
    "tags": []
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Chosen k: 11\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Test accuracy: 0.888\n"
     ]
    }
   ],
   "source": [
    "best_k = int(k_results.loc[k_results['validation accuracy'].idxmax(), 'k'])\n",
    "\n",
    "final_model = make_pipeline(StandardScaler(), KNeighborsClassifier(n_neighbors=best_k))\n",
    "final_model.fit(X_train, y_train)\n",
    "\n",
    "print('Chosen k:', best_k)\n",
    "print('Test accuracy:', round(final_model.score(X_test, y_test), 3))"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "c051",
   "metadata": {},
   "source": [
    "Validation accuracy is highest at $k = 11$ (0.899), but every $k$ from 5 to 31 is within about one percentage point of it. Differences that small are partly the luck of which sessions landed in the validation set, so any $k$ in that range is a reasonable choice. With $k = 11$, the final classifier is right for about 89% of the test sessions, compared with 85% for the always-\"no purchase\" baseline."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 29,
   "id": "c052",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2026-11-17T23:43:42.825394Z",
     "iopub.status.busy": "2026-11-17T23:43:42.825323Z",
     "iopub.status.idle": "2026-11-17T23:43:42.826773Z",
     "shell.execute_reply": "2026-11-17T23:43:42.826491Z"
    },
    "tags": [
     "thebe-interactive"
    ]
   },
   "outputs": [],
   "source": [
    "### Exercise: Compare a Few Values of k\n",
    "#   1. For k in [3, 7, 15], fit a pipeline (StandardScaler, then\n",
    "#      KNeighborsClassifier) on X_fit, y_fit and compute its accuracy on X_val, y_val.\n",
    "#   2. Print each k with its validation accuracy rounded to 3 decimals, then\n",
    "#      print the k with the highest validation accuracy.\n",
    "# Print exactly:\n",
    "# k = 3 validation accuracy: 0.886\n",
    "# k = 7 validation accuracy: 0.897\n",
    "# k = 15 validation accuracy: 0.897\n",
    "# Best k: 7\n",
    "### Your code starts here.\n",
    "\n",
    "\n",
    "\n",
    "\n",
    "### Your code ends here."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 30,
   "id": "c053",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2026-11-17T23:43:42.827604Z",
     "iopub.status.busy": "2026-11-17T23:43:42.827544Z",
     "iopub.status.idle": "2026-11-17T23:43:42.862459Z",
     "shell.execute_reply": "2026-11-17T23:43:42.862168Z"
    },
    "tags": [
     "hide-input"
    ]
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "k = 3 validation accuracy: 0.886\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "k = 7 validation accuracy: 0.897\n",
      "k = 15 validation accuracy: 0.897\n",
      "Best k: 7\n"
     ]
    }
   ],
   "source": [
    "### Solution\n",
    "ex_best_score = 0\n",
    "for ex_k in [3, 7, 15]:\n",
    "    ex_model = make_pipeline(StandardScaler(), KNeighborsClassifier(n_neighbors=ex_k))\n",
    "    ex_model.fit(X_fit, y_fit)\n",
    "    ex_score = ex_model.score(X_val, y_val)\n",
    "    print('k =', ex_k, 'validation accuracy:', round(ex_score, 3))\n",
    "    if ex_score > ex_best_score:\n",
    "        ex_best_score = ex_score\n",
    "        ex_best_k = ex_k\n",
    "\n",
    "print('Best k:', ex_best_k)"
   ]
  }
 ],
 "metadata": {
  "anaconda-cloud": {},
  "celltoolbar": "Tags",
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "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.13.16"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
