{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "f2885b56",
   "metadata": {},
   "source": [
    "### Load MNIST dataset"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "805542e2",
   "metadata": {},
   "outputs": [],
   "source": [
    "# Python ≥3.5 is required\n",
    "import sys\n",
    "assert sys.version_info >= (3, 5)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "26d38ac4",
   "metadata": {},
   "outputs": [],
   "source": [
    "# scikit-learn ≥0.20 is required\n",
    "import sklearn\n",
    "assert sklearn.__version__ >= \"0.20\""
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "749c3ec9",
   "metadata": {},
   "outputs": [],
   "source": [
    "# common imports\n",
    "import numpy as np"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "id": "810daa97",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "sklearn.utils.Bunch"
      ]
     },
     "execution_count": 4,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# import function to scikit-learn datasets\n",
    "from sklearn.datasets import fetch_openml\n",
    "\n",
    "# load specified dataset (MNIST)\n",
    "mnist = fetch_openml('mnist_784', version=1, as_frame=False)\n",
    "\n",
    "# print type of dataset\n",
    "type(mnist)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "id": "48b3d387",
   "metadata": {},
   "outputs": [],
   "source": [
    "X, y = mnist[\"data\"], mnist[\"target\"]"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "96ed2a09",
   "metadata": {},
   "source": [
    "### Fix labels"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 113,
   "id": "4c537948",
   "metadata": {},
   "outputs": [],
   "source": [
    "# import plotting libraries\n",
    "import matplotlib as mpl\n",
    "import matplotlib.pyplot as plt\n",
    "from math import isqrt, sqrt"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "id": "4d138b55",
   "metadata": {},
   "outputs": [],
   "source": [
    "# convert string labels to int\n",
    "y = y.astype(np.uint8)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 126,
   "id": "b5284df4",
   "metadata": {},
   "outputs": [],
   "source": [
    "# function to quickly plot an image\n",
    "def plot_digit(data):\n",
    "    image = data.reshape(28, 28)\n",
    "    plt.imshow(image, cmap = mpl.cm.binary, interpolation=\"nearest\")\n",
    "    plt.axis(\"off\")"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "a572aebf",
   "metadata": {},
   "source": [
    "### Prepare data for machine learning"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "3b5bc85f",
   "metadata": {},
   "source": [
    "### Identify Train Set and Test Set"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "id": "3db579b6",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "X_train: 56000, (56000, 784)\n",
      "X_test: 14000, (14000, 784)\n",
      "y_train: 56000, (56000,)\n",
      "y_test: 14000, (14000,)\n"
     ]
    }
   ],
   "source": [
    "from sklearn.model_selection import train_test_split\n",
    "\n",
    "X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=1337)\n",
    "\n",
    "print(f\"X_train: {len(X_train)}, {X_train.shape}\")\n",
    "print(f\"X_test: {len(X_test)}, {X_test.shape}\")\n",
    "print(f\"y_train: {len(y_train)}, {y_train.shape}\")\n",
    "print(f\"y_test: {len(y_test)}, {y_test.shape}\")"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "7c035dc8",
   "metadata": {},
   "source": [
    "## Pipeline Declaration"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 140,
   "id": "4bd42611",
   "metadata": {},
   "outputs": [],
   "source": [
    "from sklearn.pipeline import Pipeline\n",
    "from sklearn.decomposition import PCA\n",
    "from sklearn.preprocessing import StandardScaler, MinMaxScaler, MaxAbsScaler, Binarizer\n",
    "from sklearn.neighbors import KNeighborsClassifier\n",
    "from sklearn.model_selection import cross_val_predict\n",
    "from sklearn.metrics import classification_report, accuracy_score\n",
    "\n",
    "n_neighbors = 3\n",
    "n95_components = 0.95\n",
    "n99_components = 0.99"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 143,
   "id": "c347de5b",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(4, 4)"
      ]
     },
     "execution_count": 143,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "names = ['scaler', \n",
    "         'minmax', \n",
    "         'maxabs',\n",
    "         'bin'\n",
    "        ]\n",
    "\n",
    "classifiers = [\n",
    "    Pipeline([('scaler', StandardScaler())]),\n",
    "    Pipeline([('minmax', MinMaxScaler())]),\n",
    "    Pipeline([('maxabs', MaxAbsScaler())]),\n",
    "    Pipeline([('bin', Binarizer())]),\n",
    "]\n",
    "\n",
    "len(names), len(classifiers)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "bd566c8d",
   "metadata": {},
   "source": [
    "# Crossvalidation"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 123,
   "id": "77f6d632",
   "metadata": {},
   "outputs": [],
   "source": [
    "def cv(num):\n",
    "    name = names[num]\n",
    "    clf = classifiers[num]\n",
    "    i = 10000\n",
    "    _X_train = clf.fit_transform(X_train, y_train)\n",
    "    print(y_train[i])\n",
    "    plot_digit(_X_train[i])\n",
    "    return _X_train[i]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 128,
   "id": "bb8eb2e0",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "3\n"
     ]
    },
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAOcAAADnCAYAAADl9EEgAAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjQuMSwgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy/Z1A+gAAAACXBIWXMAAAsTAAALEwEAmpwYAAAGuElEQVR4nO3dS4jNcR/H8TOPy9ggyXVHKQtKUohsFKGsr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gglTgglTgglTgglTgglTgglTgglTgglTgglTgglTgglTgglTgglTgglTgglTgglTgglTgg1s2X/7Z8mA6aeT04IJU4IJU4IJU4IJU4IJU4I9V9xQCui+SkYGAAAAABJRU5ErkJggg==\n",
      "text/plain": [
       "<Figure size 432x288 with 1 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "i = 10000\n",
    "print(y_train[i])\n",
    "plot_digit(X_train[i])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 132,
   "id": "70f4411f",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "3\n"
     ]
    },
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAOcAAADnCAYAAADl9EEgAAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjQuMSwgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy/Z1A+gAAAACXBIWXMAAAsTAAALEwEAmpwYAAAJdElEQVR4nO3d32uOfxzH8WumyczISMx23zFR8ytRiHY4O3PqTHHIP+IPcUJxIpRi2YEQRZO1rbBi+dXNNJsN3zNHu17vtY+P6zXf5+Pw++ozt22v71XevT9X069fvwoAflZU/QEALIxyAqYoJ2CKcgKmKCdgaqUKh4aG+KdcILPjx483LfTfeXICpignYIpyAqYoJ2CKcgKmKCdginICpuSc81+1YsW/+/+kpqYFR2a/LdctpJ8/f1b9Ef66f/e3FFjmKCdginICpignYIpyAqYoJ2CKcgKm/tk5Z8osM5oVpp5XecrZqqXOUNX56OcZ/dmpn62KOStPTsAU5QRMUU7AFOUETFFOwBTlBEzZjlJS17pyjitSc/V3Szm7mPMpUscVUa7GFdEoI3XUEX029X3PNWbhyQmYopyAKcoJmKKcgCnKCZiinIApygmYqmzOmXOOGX391Flic3NzUv7hw4fSbHx8XJ4dHR2V+cjIiMx7e3tlfubMmdIs+r5F8765ubkln//x44c8G+Wpc9KUdbalzkF5cg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+WZ589eybz169fy3x4eFjmamczmu9Gu6Tnz5+X+dq1a0uz1Dlm6pwz56sRy/DkBExRTsAU5QRMUU7AFOUETFFOwBTlBExlnXOq+U90P2uVc6nUGWr0Ojo1L4zmu/V6Xea1Wk3mx44dk7n6u0e7pKl7siqvco65mK+fA09OwBTlBExRTsAU5QRMUU7AFOUETFFOwJTt+zlT9z2V1JlWNO+LZrhRnlPKPDB1lpgyq6zyfa1V4ckJmKKcgCnKCZiinIApygmYopyAqcpGKdE/q0fjhpwrPqlfOxrzpIyBUqWMHHKPM1LGHamjkipWwiI8OQFTlBMwRTkBU5QTMEU5AVOUEzBFOQFTy3ZlLKLmpNEVjalyzjFzz0irnDUqjnPI3HhyAqYoJ2CKcgKmKCdginICpignYIpyAqaaluOVgcD/AU9OwBTlBExRTsAU5QRMUU7AFOUETP0Hj4dT7WBQ3HQAAAAASUVORK5CYII=\n",
      "text/plain": [
       "<Figure size 432x288 with 1 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "a = cv(0)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 133,
   "id": "70f3533d",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "3\n"
     ]
    },
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAOcAAADnCAYAAADl9EEgAAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjQuMSwgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy/Z1A+gAAAACXBIWXMAAAsTAAALEwEAmpwYAAAGuElEQVR4nO3dS4jNcR/H8TOPy9ggyXVHKQtKUohsFKGsrWRBiFwWMxasXGpqIpKVHaVcFoqdLGaShYUdi9lYTIlYSFEUnt2z8v/+e87MmM/h9Vr69Dtzanp3yq/zn75fv351gDz/me43APyeOCGUOCGUOCGUOCHUzJbdf+XC1Ov73T/65IRQ4oRQ4oRQ4oRQ4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v5V49WvPMmTPl2bdv35b7z58/y31oaKhxGxwcLM9O5f3tH+CeE3qJOCGUOCGUOCGUOCGUOCGUOCGUe85p8PTp08Zt/vz55dkNGzZM9tuZNNXzeDudTmdgYKDr175z506579u3r+vXDuCeE3qJOCGUOCGUOCGUOCGUOCGUOCGUe04mzbt378q97Y62+j7o9u3by7NPnjwp93DuOaGXiBNCiRNCiRNCiRNCiRNCzZzuN8DfY+nSpeV+7Nixcj979uxkvp2e55MTQokTQokTQokTQokTQokTQokTQvnKWBfGxsbK/eDBg+W+ZcuWxu3ixYvl2RkzZpR7spcvX5Z79ZWyefPmlWfHx8fLfe7cueU+zXxlDHqJOCGUOCGUOCGUOCGUOCGUOCGU73N24fbt2+X+7NmzrveVK1eWZw8dOlTuyV6/ft312UWLFpX7rFmzun7tVD45IZQ4IZQ4IZQ4IZQ4IZQ4IZQ4IZR7zi5s3Lix3Pv7+8v927dvjdvp06fLs5s3by73NWvWlPtU+vr1a7m33Q9X1q9fX+5z5szp+rVT+eSEUOKEUOKEUOKEUOKEUOKEUB6NOQXu379f7vv372/cqmuWTqf9ymDt2rXlfvLkyXKv/ozfly9fyrNXrlwp95GRkXKfP39+4/bq1avy7PLly8s9nEdjQi8RJ4QSJ4QSJ4QSJ4QSJ4QSJ4RyzzkNRkdHG7c9e/aUZ9vuGlt+n52+vt9eqf0R1T1mp9PpPHr0qHHbunXrZL+dJO45oZeIE0KJE0KJE0KJE0KJE0KJE0K55wzT9n3OGzdulHvbnx98+PBhuVffF123bl15dvXq1eU+PDxc7gsXLiz3v5h7Tugl4oRQ4oRQ4oRQ4oRQ4oRQ4oRQ7jlh+rnnhF4iTgglTgglTgglTgglTgglTgglTgglTgglTgglTgglTgglTgglTgglTgglTgglTgglTgglTgglTgglTgglTgglTgglTgglTgglTgglTgglTgglTgglTgg1s2X/7Z8mA6aeT04IJU4IJU4IJU4IJU4IJU4I9V9xQCui+SkYGAAAAABJRU5ErkJggg==\n",
      "text/plain": [
       "<Figure size 432x288 with 1 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "a = cv(1)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 134,
   "id": "2ec8d300",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "3\n"
     ]
    },
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAOcAAADnCAYAAADl9EEgAAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjQuMSwgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy/Z1A+gAAAACXBIWXMAAAsTAAALEwEAmpwYAAAGuElEQVR4nO3dS4jNcR/H8TOPy9ggyXVHKQtKUohsFKGsrWRBiFwWMxasXGpqIpKVHaVcFoqdLGaShYUdi9lYTIlYSFEUnt2z8v/+e87MmM/h9Vr69Dtzanp3yq/zn75fv351gDz/me43APyeOCGUOCGUOCGUOCHUzJbdf+XC1Ov73T/65IRQ4oRQ4oRQ4oRQ4oRQ4oRQ4oRQ4oRQ4oRQ4oRQ4oRQ4oRQ4oRQ4oRQ4oRQ4oRQ4oRQ4oRQ4oRQ4oRQ4oRQ4oRQ4oRQ4oRQ4oRQ4oRQ4oRQ4oRQ4oRQ4oRQbX8CkCkwPj7euI2MjJRnHz16VO737t0r9x07dpT748ePG7dZs2aVZ5lcPjkhlDghlDghlDghlDghlDghlDghVN+vX7+qvRz/Vrdv3y73u3fvTuj1nz592rh9+/ZtQq/d8vvs9PX1lfvu3bsbt4cPH5ZnZ850bd6l3/5SfHJCKHFCKHFCKHFCKHFCKHFCKHFCqH/ynvPWrVvlfuLEiXL//PnzhH7+zp07G7dVq1aVZ/fu3Vvu169fL/e274NWhoaGyn1wcLDr1/7HueeEXiJOCCVOCCVOCCVOCCVOCNWzVyk/fvwo9wsXLjRuV69eLc+2XZX09/eX+8DAQLmfO3eucZs9e3Z5ts3Pnz/Lfdu2beX+/Pnzxm3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by73NWvWlPtU+vr1a7m33Q9X1q9fX+5z5szp+rVT+eSEUOKEUOKEUOKEUOKEUOKEUB6NOQXu379f7vv372/cqmuWTqf9ymDt2rXlfvLkyXKv/ozfly9fyrNXrlwp95GRkXKfP39+4/bq1avy7PLly8s9nEdjQi8RJ4QSJ4QSJ4QSJ4QSJ4QSJ4RyzzkNRkdHG7c9e/aUZ9vuGlt+n52+vt9eqf0R1T1mp9PpPHr0qHHbunXrZL+dJO45oZeIE0KJE0KJE0KJE0KJE0KJE0K55wzT9n3OGzdulHvbnx98+PBhuVffF123bl15dvXq1eU+PDxc7gsXLiz3v5h7Tugl4oRQ4oRQ4oRQ4oRQ4oRQ4oRQ7jlh+rnnhF4iTgglTgglTgglTgglTgglTgglTgglTgglTgglTgglTgglTgglTgglTgglTgglTgglTgglTgglTgglTgglTgglTgglTgglTgglTgglTgglTgglTgglTgg1s2X/7Z8mA6aeT04IJU4IJU4IJU4IJU4IJU4I9V9xQCui+SkYGAAAAABJRU5ErkJggg==\n",
      "text/plain": [
       "<Figure size 432x288 with 1 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "a = cv(2)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 137,
   "id": "b1f285c2",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "3\n",
      "3\n"
     ]
    },
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAOcAAADnCAYAAADl9EEgAAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjQuMSwgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy/Z1A+gAAAACXBIWXMAAAsTAAALEwEAmpwYAAADaklEQVR4nO3dQWqDUBRAUX/JwrI0l5ad2VHpRCJto17Tc4aVgB1cHuTx88eyLBPQ83H2CwDrxAlR4oQocUKUOCHqtvHcV7mwv7H2R5MTosQJUeKEKHFClDghSpwQJU6IEidEiROixAlR4oQocUKUOCFKnBAlTogSJ0SJE6LECVHihChxQpQ4IUqcECVOiBInRIkTosQJUeKEKHFClDghSpwQJU6IEidEiROixAlR4oQocUKUOCFKnBB1O/sFrmiM8afPL8vyojd5vWf/W/m935HJCVHihChxQpQ4IUqcECVOiBInRI2N3ZXFFuxvdblsckKUOCFKnBAlTogSJ0SJE6IcGftnto67ORbWYXJClDghSpwQJU6IEidEiROixAlRl91zPh6Pp8/v9/sh73E1f9lj2pEey+SEKHFClDghSpwQJU6IEidEiROiLrvn3JMd6jp7zGOZnBAlTogSJ0SJE6LECVHihChxQpQrAOF8rgCEKxEnRIkTosQJUeKEKHFClDghSpwQJU6IEidEiROixAlR4oQocUKUOCFKnBAlTogSJ0SJE6LECVHihChxQpQrAE8wxuovIU7T5Jo9vpmcECVOiBInRIkTosQJUeKEKHFClD3nCcq7zHmef/WM1zM5IUqcECVOiBInRIkTosQJUeKEqLGxc+su5OB9rB7wNTkhSpwQJU6IEidEiROixAlR4oQo5zk5zLPf652m9jnXM5icECVOiBInRIkTosQJUeKEKKsUDmNV8jMmJ0SJE6LECVHihChxQpQ4IUqcECVOiBInRIkTosQJUeKEKHFClDghSpwQJU6IEidEiROixAlR4oQocUKUOCFKnBDld2tjXJPHF5MTosQJUeKEKHFClDghSpwQZZUSs/eqZJ7nUz7Lz5mcECVOiBInRIkTosQJUeKEKHFC1NjYqzmfBPtbPSdockKUOCFKnBAlTogSJ0SJE6LECVHOc17M1plKZy7fh8kJUeKEKHFClDghSpwQJU6IEidEOc8J53OeE65EnBAlTogSJ0SJE6LECVHihChxQpQ4IUqcECVOiBInRIkTosQJUeKEKHFClDghSpwQJU6IEidEiROixAlR4oQocUKUOCFKnBAlTogSJ0SJE6LECVG3jeerV5MB+zM5IUqcECVOiBInRIkTosQJUZ8VcUzDwD2AfQAAAABJRU5ErkJggg==\n",
      "text/plain": [
       "<Figure size 432x288 with 1 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "plot_digit(cv(2)-cv(1))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 145,
   "id": "2c7323b6",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "3\n"
     ]
    },
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAOcAAADnCAYAAADl9EEgAAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjQuMSwgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy/Z1A+gAAAACXBIWXMAAAsTAAALEwEAmpwYAAADlUlEQVR4nO3dwWrbQBhG0ar0/V9ZWWURIjzU9lh3pHOW7cY4XH7Ih6Jt3/c/QM/fsz8AcEycECVOiBInRIkTov4N/t+vcmG+7egfXU6IEidEiROixAlR4oQocUKUOCFKnBAlTogSJ0SJE6LECVHihChxQpQ4IUqcECVOiBInRIkTosQJUeKEKHFClDghSpwQJU6IEidEiROixAlR4oQocULU6BWATLBth298y9t3b4T8JJcTosQJUeKEKHFClDghSpwQJU6IsnMeWHWHnG30vdhB38vlhChxQpQ4IUqcECVOiBInRIkTom65c9oxWYHLCVHihChxQpQ4IUqcECVOiFp2SrnqHPLqY1dX/V7uyOWEKHFClDghSpwQJU6IEidEiROilt05y/yJSN7B5YQocUKUOCFKnBAlTogSJ0SJE6LsnE+wY/IJLidEiROixAlR4oQocUKUOCFKnBC17M452hof/f1WOyUrcDkhSpwQJU6IEidEiROixAlR4oSoZXfOkVW3zPL7NVf9TlflckKUOCFKnBAlTogSJ0SJE6IuO6WUleeSR1793KaY/+NyQpQ4IUqcECVOiBInRIkTosQJUXbOCVbdMWcbfS920J9cTogSJ0SJE6LECVHihChxQpQ4IWobbEuGpwlm7qCvvBpxZYtvpIc/FJcTosQJUeKEKHFClDghSpwQJU6I8jznYl7d82bugVfdUM/ickKUOCFKnBAlTogSJ0SJE6LECVF2zhMs/uwhH+JyQpQ4IUqcECVOiBInRIkTokwpvM1d/yznLC4nRIkTosQJUeKEKHFClDghSpwQZed8wpl7ncfNjo1+Jit+by4nRIkTosQJUeKEKHFClDghSpwQJU6IEidEiROixAlR4oQocUKUOCFKnBDlec7FlJ9b9Jzre7mcECVOiBInRIkTosQJUeKEKFPKE8qvuvOavetwOSFKnBAlTogSJ0SJE6LECVHihCg75wTlHXRVV3wkbMTlhChxQpQ4IUqcECVOiBInRIkTouycJ3i02d15A73jlvmIywlR4oQocUKUOCFKnBAlTogSJ0TZOWNsfXxzOSFKnBAlTogSJ0SJE6LECVHihChxQpQ4IUqcECVOiBInRIkTosQJUeKEKHFClDghSpwQJU6IEidEiROixAlR4oQocUKUOCFKnBAlTogSJ0SJE6LECVGjVwBuH/kUwC8uJ0SJE6LECVHihChxQpQ4IeoLGL5a6fFroA8AAAAASUVORK5CYII=\n",
      "text/plain": [
       "<Figure size 432x288 with 1 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "a = cv(3)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "b608bd89",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "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.8.5"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
