{"metadata":{"kernelspec":{"language":"python","display_name":"Python 3","name":"python3"},"language_info":{"name":"python","version":"3.10.13","mimetype":"text/x-python","codemirror_mode":{"name":"ipython","version":3},"pygments_lexer":"ipython3","nbconvert_exporter":"python","file_extension":".py"},"kaggle":{"accelerator":"none","dataSources":[{"sourceId":3004,"databundleVersionId":861823,"sourceType":"competition"}],"dockerImageVersionId":30673,"isInternetEnabled":false,"language":"python","sourceType":"notebook","isGpuEnabled":false}},"nbformat_minor":4,"nbformat":4,"cells":[{"cell_type":"code","source":"# This Python 3 environment comes with many helpful analytics libraries installed\n# It is defined by the kaggle/python Docker image: https://github.com/kaggle/docker-python\n# For example, here's several helpful packages to load\n\nimport numpy as np # linear algebra\nimport pandas as pd # data processing, CSV file I/O (e.g. pd.read_csv)\n\n# Input data files are available in the read-only \"../input/\" directory\n# For example, running this (by clicking run or pressing Shift+Enter) will list all files under the input directory\n\nimport os\nfor dirname, _, filenames in os.walk('/kaggle/input'):\n    for filename in filenames:\n        print(os.path.join(dirname, filename))\n\n# You can write up to 20GB to the current directory (/kaggle/working/) that gets preserved as output when you create a version using \"Save & Run All\" \n# You can also write temporary files to /kaggle/temp/, but they won't be saved outside of the current session","metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","execution":{"iopub.status.busy":"2024-03-30T18:48:20.312437Z","iopub.execute_input":"2024-03-30T18:48:20.312928Z","iopub.status.idle":"2024-03-30T18:48:20.32256Z","shell.execute_reply.started":"2024-03-30T18:48:20.312884Z","shell.execute_reply":"2024-03-30T18:48:20.321441Z"},"trusted":true},"execution_count":43,"outputs":[{"name":"stdout","text":"/kaggle/input/digit-recognizer/sample_submission.csv\n/kaggle/input/digit-recognizer/train.csv\n/kaggle/input/digit-recognizer/test.csv\n","output_type":"stream"}]},{"cell_type":"code","source":"df = pd.read_csv('/kaggle/input/digit-recognizer/train.csv')","metadata":{"execution":{"iopub.status.busy":"2024-03-30T18:48:20.324138Z","iopub.execute_input":"2024-03-30T18:48:20.32462Z","iopub.status.idle":"2024-03-30T18:48:22.895728Z","shell.execute_reply.started":"2024-03-30T18:48:20.324579Z","shell.execute_reply":"2024-03-30T18:48:22.894587Z"},"trusted":true},"execution_count":44,"outputs":[]},{"cell_type":"code","source":"df.shape","metadata":{"execution":{"iopub.status.busy":"2024-03-30T18:48:22.89864Z","iopub.execute_input":"2024-03-30T18:48:22.899464Z","iopub.status.idle":"2024-03-30T18:48:22.905887Z","shell.execute_reply.started":"2024-03-30T18:48:22.89943Z","shell.execute_reply":"2024-03-30T18:48:22.904649Z"},"trusted":true},"execution_count":45,"outputs":[{"execution_count":45,"output_type":"execute_result","data":{"text/plain":"(42000, 785)"},"metadata":{}}]},{"cell_type":"code","source":"df.sample(3)","metadata":{"execution":{"iopub.status.busy":"2024-03-30T18:48:22.90709Z","iopub.execute_input":"2024-03-30T18:48:22.907515Z","iopub.status.idle":"2024-03-30T18:48:22.93156Z","shell.execute_reply.started":"2024-03-30T18:48:22.907474Z","shell.execute_reply":"2024-03-30T18:48:22.930406Z"},"trusted":true},"execution_count":46,"outputs":[{"execution_count":46,"output_type":"execute_result","data":{"text/plain":"       label  pixel0  pixel1  pixel2  pixel3  pixel4  pixel5  pixel6  pixel7  \\\n3151       5       0       0       0       0       0       0       0       0   \n20179      0       0       0       0       0       0       0       0       0   \n22067      9       0       0       0       0       0       0       0       0   \n\n       pixel8  ...  pixel774  pixel775  pixel776  pixel777  pixel778  \\\n3151        0  ...         0         0         0         0         0   \n20179       0  ...         0         0         0         0         0   \n22067       0  ...         0         0         0         0         0   \n\n       pixel779  pixel780  pixel781  pixel782  pixel783  \n3151          0         0         0         0         0  \n20179         0         0         0         0         0  \n22067         0         0         0         0         0  \n\n[3 rows x 785 columns]","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>label</th>\n      <th>pixel0</th>\n      <th>pixel1</th>\n      <th>pixel2</th>\n      <th>pixel3</th>\n      <th>pixel4</th>\n      <th>pixel5</th>\n      <th>pixel6</th>\n      <th>pixel7</th>\n      <th>pixel8</th>\n      <th>...</th>\n      <th>pixel774</th>\n      <th>pixel775</th>\n      <th>pixel776</th>\n      <th>pixel777</th>\n      <th>pixel778</th>\n      <th>pixel779</th>\n      <th>pixel780</th>\n      <th>pixel781</th>\n      <th>pixel782</th>\n      <th>pixel783</th>\n    </tr>\n  </thead>\n  <tbody>\n    <tr>\n      <th>3151</th>\n      <td>5</td>\n      <td>0</td>\n      <td>0</td>\n      <td>0</td>\n      <td>0</td>\n      <td>0</td>\n      <td>0</td>\n      <td>0</td>\n      <td>0</td>\n      <td>0</td>\n      <td>...</td>\n      <td>0</td>\n      <td>0</td>\n      <td>0</td>\n      <td>0</td>\n      <td>0</td>\n      <td>0</td>\n      <td>0</td>\n      <td>0</td>\n      <td>0</td>\n      <td>0</td>\n    </tr>\n    <tr>\n      <th>20179</th>\n      <td>0</td>\n      <td>0</td>\n      <td>0</td>\n      <td>0</td>\n      <td>0</td>\n      <td>0</td>\n      <td>0</td>\n      <td>0</td>\n      <td>0</td>\n      <td>0</td>\n      <td>...</td>\n      <td>0</td>\n      <td>0</td>\n      <td>0</td>\n      <td>0</td>\n      <td>0</td>\n      <td>0</td>\n      <td>0</td>\n      <td>0</td>\n      <td>0</td>\n      <td>0</td>\n    </tr>\n    <tr>\n      <th>22067</th>\n      <td>9</td>\n      <td>0</td>\n      <td>0</td>\n      <td>0</td>\n      <td>0</td>\n      <td>0</td>\n      <td>0</td>\n      <td>0</td>\n      <td>0</td>\n      <td>0</td>\n      <td>...</td>\n      <td>0</td>\n      <td>0</td>\n      <td>0</td>\n      <td>0</td>\n      <td>0</td>\n      <td>0</td>\n      <td>0</td>\n      <td>0</td>\n      <td>0</td>\n      <td>0</td>\n    </tr>\n  </tbody>\n</table>\n<p>3 rows × 785 columns</p>\n</div>"},"metadata":{}}]},{"cell_type":"code","source":"import matplotlib.pyplot as plt\nplt.imshow(df.iloc[28270,1:].values.reshape(28,28))","metadata":{"execution":{"iopub.status.busy":"2024-03-30T18:48:22.935835Z","iopub.execute_input":"2024-03-30T18:48:22.93615Z","iopub.status.idle":"2024-03-30T18:48:23.177257Z","shell.execute_reply.started":"2024-03-30T18:48:22.936124Z","shell.execute_reply":"2024-03-30T18:48:23.176109Z"},"trusted":true},"execution_count":47,"outputs":[{"execution_count":47,"output_type":"execute_result","data":{"text/plain":"<matplotlib.image.AxesImage at 0x7ee61d8cd720>"},"metadata":{}},{"output_type":"display_data","data":{"text/plain":"<Figure size 640x480 with 1 Axes>","image/png":"iVBORw0KGgoAAAANSUhEUgAAAaAAAAGdCAYAAABU0qcqAAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjcuNSwgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy/xnp5ZAAAACXBIWXMAAA9hAAAPYQGoP6dpAAAcI0lEQVR4nO3df3DU9b3v8dcGwgKaLIaQXyVgAIUqEq8UYg5KUVJC7GVAGY+oPRc4XhwwOMX4q+lV0bYzafGMtXpSPHOvhXoqqJwKXBmLg8GEoSYoEQ6X0zaH0FjCkITKbbIhmBDI5/7BdXUlAb/rbt5JeD5mvjNk9/vO9+PXHZ9+2c03PuecEwAAvSzOegEAgEsTAQIAmCBAAAATBAgAYIIAAQBMECAAgAkCBAAwQYAAACYGWy/gy7q6unTs2DElJCTI5/NZLwcA4JFzTq2trcrIyFBcXM/XOX0uQMeOHVNmZqb1MgAAX1N9fb1Gjx7d4/N9LkAJCQmSpJt0mwYr3ng1AACvzqhTu/V26L/nPYlZgEpLS/Xss8+qsbFR2dnZevHFFzV9+vSLzn32126DFa/BPgIEAP3O/7/D6MXeRonJhxBef/11FRU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frw0ys9z/y3xPc8z7xxcrTnmV89sMDzzOBgtecZoLdwBQQAMEGAAAAmCBAAwAQBAgCYIEAAABMECABgggABAEwQIACACQIEADBBgAAAJggQAMAEAQIAmOBmpIhYV3u755krvnvI88xtusHzTG96Q2m9cpzB4saiGFi4AgIAmCBAAAATBAgAYIIAAQBMECAAgAkCBAAwQYAAACYIEADABAECAJggQAAAEwQIAGCCAAEATBAgAIAJAgQAMEGAAAAmPAWopKRE06ZNU0JCglJSUrRgwQLV1NSE7TNr1iz5fL6wbfny5VFdNACg//MUoIqKChUWFqqqqko7duxQZ2en5syZo7a2trD9li1bpoaGhtC2Zs2aqC4aAND/efqNqNu3bw/7ev369UpJSVF1dbVmzpwZenz48OFKS+ud3xIJAOifvtZ7QC0tLZKkpKSksMdfffVVJScna/LkySouLtapU6d6/B4dHR0KBoNhGwBg4PN0BfRFXV1dWrVqlWbMmKHJkyeHHr/nnns0duxYZWRk6MCBA3r88cdVU1OjN998s9vvU1JSomeeeSbSZQAA+imfc85FMrhixQr97ne/0+7duzV69Oge99u5c6dmz56t2tpajR8//rznOzo61NHREfo6GAwqMzNTszRfg33xkSwNAGDojOtUubaqpaVFiYmJPe4X0RXQypUrtW3bNu3ateuC8ZGknJwcSeoxQH6/X36/P5JlAAD6MU8Bcs7pwQcf1ObNm1VeXq6srKyLzuzfv1+SlJ6eHtECAQADk6cAFRYWasOGDdq6dasSEhLU2NgoSQoEAho2bJgOHz6sDRs26LbbbtPIkSN14MABPfTQQ5o5c6amTJkSk38AAED/5Ok9IJ/P1+3j69at05IlS1RfX6/vfe97OnjwoNra2pSZmanbb79dTzzxxAX/HvCLgsGgAoEA7wEBQD8Vk/eALtaqzMxMVVRUePmWAIBLFPeCAwCYIEAAABMECABgggABAEwQIACACQIEADBBgAAAJggQAMAEAQIAmCBAAAATBAgAYIIAAQBMECAAgAkCBAAwQYAAACYIEADABAECAJggQAAAEwQIAGCCAAEATBAgAIAJAgQAMEGAAAAmCBAAwAQBAgCYGGy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smHvvvfecpPO2xYsXO+fOfRT7ySefdKmpqc7v97vZs2e7mpoa20XHwIXOw6lTp9ycOXPcqFGjXHx8vBs7dqxbtmzZgPuftO7++SW5devWhfb59NNP3QMPPOCuuOIKN3z4cHf77be7hoYGu0XHwMXOw5EjR9zMmTNdUlKS8/v9bsKECe7RRx91LS0ttgv/En4dAwDARJ9/DwgAMDARIACACQIEADBBgAAAJggQAMAEAQIAmCBAAAATBAgAYIIAAQBMECAAgAkCBAAwQYAAACb+H1Dm0nycj/OJAAAAAElFTkSuQmCC"},"metadata":{}}]},{"cell_type":"code","source":"X = df.iloc[:,1:]\ny = df.iloc[:,0]","metadata":{"execution":{"iopub.status.busy":"2024-03-30T18:48:23.178489Z","iopub.execute_input":"2024-03-30T18:48:23.17884Z","iopub.status.idle":"2024-03-30T18:48:23.185673Z","shell.execute_reply.started":"2024-03-30T18:48:23.17881Z","shell.execute_reply":"2024-03-30T18:48:23.184722Z"},"trusted":true},"execution_count":48,"outputs":[]},{"cell_type":"code","source":"from sklearn.model_selection import train_test_split\nX_train,X_test,y_train,y_test=train_test_split(X,y,test_size=0.2,random_state=42)\nX_train.shape","metadata":{"execution":{"iopub.status.busy":"2024-03-30T18:48:23.186775Z","iopub.execute_input":"2024-03-30T18:48:23.18733Z","iopub.status.idle":"2024-03-30T18:48:23.454859Z","shell.execute_reply.started":"2024-03-30T18:48:23.187266Z","shell.execute_reply":"2024-03-30T18:48:23.453784Z"},"trusted":true},"execution_count":49,"outputs":[{"execution_count":49,"output_type":"execute_result","data":{"text/plain":"(33600, 784)"},"metadata":{}}]},{"cell_type":"code","source":"from sklearn.neighbors import KNeighborsClassifier\nknn = KNeighborsClassifier()","metadata":{"execution":{"iopub.status.busy":"2024-03-30T18:48:23.456084Z","iopub.execute_input":"2024-03-30T18:48:23.456414Z","iopub.status.idle":"2024-03-30T18:48:23.461411Z","shell.execute_reply.started":"2024-03-30T18:48:23.456386Z","shell.execute_reply":"2024-03-30T18:48:23.460403Z"},"trusted":true},"execution_count":50,"outputs":[]},{"cell_type":"code","source":"knn.fit(X_train,y_train)","metadata":{"execution":{"iopub.status.busy":"2024-03-30T18:48:23.462558Z","iopub.execute_input":"2024-03-30T18:48:23.46354Z","iopub.status.idle":"2024-03-30T18:48:23.619003Z","shell.execute_reply.started":"2024-03-30T18:48:23.463499Z","shell.execute_reply":"2024-03-30T18:48:23.617917Z"},"trusted":true},"execution_count":51,"outputs":[{"execution_count":51,"output_type":"execute_result","data":{"text/plain":"KNeighborsClassifier()","text/html":"<style>#sk-container-id-4 {color: black;background-color: white;}#sk-container-id-4 pre{padding: 0;}#sk-container-id-4 div.sk-toggleable {background-color: white;}#sk-container-id-4 label.sk-toggleable__label {cursor: pointer;display: block;width: 100%;margin-bottom: 0;padding: 0.3em;box-sizing: border-box;text-align: center;}#sk-container-id-4 label.sk-toggleable__label-arrow:before {content: \"▸\";float: left;margin-right: 0.25em;color: #696969;}#sk-container-id-4 label.sk-toggleable__label-arrow:hover:before {color: black;}#sk-container-id-4 div.sk-estimator:hover label.sk-toggleable__label-arrow:before {color: black;}#sk-container-id-4 div.sk-toggleable__content {max-height: 0;max-width: 0;overflow: hidden;text-align: left;background-color: #f0f8ff;}#sk-container-id-4 div.sk-toggleable__content pre {margin: 0.2em;color: black;border-radius: 0.25em;background-color: #f0f8ff;}#sk-container-id-4 input.sk-toggleable__control:checked~div.sk-toggleable__content {max-height: 200px;max-width: 100%;overflow: auto;}#sk-container-id-4 input.sk-toggleable__control:checked~label.sk-toggleable__label-arrow:before {content: \"▾\";}#sk-container-id-4 div.sk-estimator input.sk-toggleable__control:checked~label.sk-toggleable__label {background-color: #d4ebff;}#sk-container-id-4 div.sk-label input.sk-toggleable__control:checked~label.sk-toggleable__label {background-color: #d4ebff;}#sk-container-id-4 input.sk-hidden--visually {border: 0;clip: rect(1px 1px 1px 1px);clip: rect(1px, 1px, 1px, 1px);height: 1px;margin: -1px;overflow: hidden;padding: 0;position: absolute;width: 1px;}#sk-container-id-4 div.sk-estimator {font-family: monospace;background-color: #f0f8ff;border: 1px dotted black;border-radius: 0.25em;box-sizing: border-box;margin-bottom: 0.5em;}#sk-container-id-4 div.sk-estimator:hover {background-color: #d4ebff;}#sk-container-id-4 div.sk-parallel-item::after {content: \"\";width: 100%;border-bottom: 1px solid gray;flex-grow: 1;}#sk-container-id-4 div.sk-label:hover label.sk-toggleable__label {background-color: #d4ebff;}#sk-container-id-4 div.sk-serial::before {content: \"\";position: absolute;border-left: 1px solid gray;box-sizing: border-box;top: 0;bottom: 0;left: 50%;z-index: 0;}#sk-container-id-4 div.sk-serial {display: flex;flex-direction: column;align-items: center;background-color: white;padding-right: 0.2em;padding-left: 0.2em;position: relative;}#sk-container-id-4 div.sk-item {position: relative;z-index: 1;}#sk-container-id-4 div.sk-parallel {display: flex;align-items: stretch;justify-content: center;background-color: white;position: relative;}#sk-container-id-4 div.sk-item::before, #sk-container-id-4 div.sk-parallel-item::before {content: \"\";position: absolute;border-left: 1px solid gray;box-sizing: border-box;top: 0;bottom: 0;left: 50%;z-index: -1;}#sk-container-id-4 div.sk-parallel-item {display: flex;flex-direction: column;z-index: 1;position: relative;background-color: white;}#sk-container-id-4 div.sk-parallel-item:first-child::after {align-self: flex-end;width: 50%;}#sk-container-id-4 div.sk-parallel-item:last-child::after {align-self: flex-start;width: 50%;}#sk-container-id-4 div.sk-parallel-item:only-child::after {width: 0;}#sk-container-id-4 div.sk-dashed-wrapped {border: 1px dashed gray;margin: 0 0.4em 0.5em 0.4em;box-sizing: border-box;padding-bottom: 0.4em;background-color: white;}#sk-container-id-4 div.sk-label label {font-family: monospace;font-weight: bold;display: inline-block;line-height: 1.2em;}#sk-container-id-4 div.sk-label-container {text-align: center;}#sk-container-id-4 div.sk-container {/* jupyter's `normalize.less` sets `[hidden] { display: none; }` but bootstrap.min.css set `[hidden] { display: none !important; }` so we also need the `!important` here to be able to override the default hidden behavior on the sphinx rendered scikit-learn.org. See: https://github.com/scikit-learn/scikit-learn/issues/21755 */display: inline-block !important;position: relative;}#sk-container-id-4 div.sk-text-repr-fallback {display: none;}</style><div id=\"sk-container-id-4\" class=\"sk-top-container\"><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 sk-toggleable\"><input class=\"sk-toggleable__control sk-hidden--visually\" id=\"sk-estimator-id-4\" type=\"checkbox\" checked><label for=\"sk-estimator-id-4\" class=\"sk-toggleable__label sk-toggleable__label-arrow\">KNeighborsClassifier</label><div class=\"sk-toggleable__content\"><pre>KNeighborsClassifier()</pre></div></div></div></div></div>"},"metadata":{}}]},{"cell_type":"code","source":"import time\nstart = time.time()\ny_pred = knn.predict(X_test)  # esko execute hone me kitna time lga uske li time import kra hai\nprint(time.time() - start)","metadata":{"execution":{"iopub.status.busy":"2024-03-30T18:48:23.623247Z","iopub.execute_input":"2024-03-30T18:48:23.624125Z","iopub.status.idle":"2024-03-30T18:48:35.760728Z","shell.execute_reply.started":"2024-03-30T18:48:23.624045Z","shell.execute_reply":"2024-03-30T18:48:35.759561Z"},"trusted":true},"execution_count":52,"outputs":[{"name":"stdout","text":"12.131618738174438\n","output_type":"stream"}]},{"cell_type":"code","source":"from sklearn.metrics import accuracy_score\naccuracy_score(y_test,y_pred)","metadata":{"execution":{"iopub.status.busy":"2024-03-30T18:48:35.765622Z","iopub.execute_input":"2024-03-30T18:48:35.765974Z","iopub.status.idle":"2024-03-30T18:48:35.774645Z","shell.execute_reply.started":"2024-03-30T18:48:35.765946Z","shell.execute_reply":"2024-03-30T18:48:35.773455Z"},"trusted":true},"execution_count":53,"outputs":[{"execution_count":53,"output_type":"execute_result","data":{"text/plain":"0.9648809523809524"},"metadata":{}}]},{"cell_type":"code","source":"from sklearn.preprocessing import StandardScaler  # now we are going to standrize data as per steps\nscaler = StandardScaler()","metadata":{"execution":{"iopub.status.busy":"2024-03-30T18:48:35.77617Z","iopub.execute_input":"2024-03-30T18:48:35.776917Z","iopub.status.idle":"2024-03-30T18:48:35.786916Z","shell.execute_reply.started":"2024-03-30T18:48:35.776876Z","shell.execute_reply":"2024-03-30T18:48:35.785724Z"},"trusted":true},"execution_count":54,"outputs":[]},{"cell_type":"code","source":"X_train = scaler.fit_transform(X_train)\nX_test = scaler.transform(X_test)","metadata":{"execution":{"iopub.status.busy":"2024-03-30T18:48:35.788921Z","iopub.execute_input":"2024-03-30T18:48:35.789326Z","iopub.status.idle":"2024-03-30T18:48:36.304865Z","shell.execute_reply.started":"2024-03-30T18:48:35.789289Z","shell.execute_reply":"2024-03-30T18:48:36.303888Z"},"trusted":true},"execution_count":55,"outputs":[]},{"cell_type":"code","source":"# PCA \nfrom sklearn.decomposition import PCA\npca = PCA(n_components=200)","metadata":{"execution":{"iopub.status.busy":"2024-03-30T18:48:36.306052Z","iopub.execute_input":"2024-03-30T18:48:36.30638Z","iopub.status.idle":"2024-03-30T18:48:36.311279Z","shell.execute_reply.started":"2024-03-30T18:48:36.306337Z","shell.execute_reply":"2024-03-30T18:48:36.31015Z"},"trusted":true},"execution_count":56,"outputs":[]},{"cell_type":"code","source":"X_train_trf = pca.fit_transform(X_train)\nX_test_trf = pca.transform(X_test)","metadata":{"execution":{"iopub.status.busy":"2024-03-30T18:48:36.312391Z","iopub.execute_input":"2024-03-30T18:48:36.312699Z","iopub.status.idle":"2024-03-30T18:48:41.275671Z","shell.execute_reply.started":"2024-03-30T18:48:36.31267Z","shell.execute_reply":"2024-03-30T18:48:41.274454Z"},"trusted":true},"execution_count":57,"outputs":[]},{"cell_type":"code","source":"X_train_trf.shape","metadata":{"execution":{"iopub.status.busy":"2024-03-30T18:48:41.277437Z","iopub.execute_input":"2024-03-30T18:48:41.278109Z","iopub.status.idle":"2024-03-30T18:48:41.284593Z","shell.execute_reply.started":"2024-03-30T18:48:41.278068Z","shell.execute_reply":"2024-03-30T18:48:41.283577Z"},"trusted":true},"execution_count":58,"outputs":[{"execution_count":58,"output_type":"execute_result","data":{"text/plain":"(33600, 200)"},"metadata":{}}]},{"cell_type":"code","source":"knn = KNeighborsClassifier()\nknn.fit(X_train_trf,y_train)","metadata":{"execution":{"iopub.status.busy":"2024-03-30T18:48:41.286407Z","iopub.execute_input":"2024-03-30T18:48:41.287013Z","iopub.status.idle":"2024-03-30T18:48:41.352441Z","shell.execute_reply.started":"2024-03-30T18:48:41.286977Z","shell.execute_reply":"2024-03-30T18:48:41.351223Z"},"trusted":true},"execution_count":59,"outputs":[{"execution_count":59,"output_type":"execute_result","data":{"text/plain":"KNeighborsClassifier()","text/html":"<style>#sk-container-id-5 {color: black;background-color: white;}#sk-container-id-5 pre{padding: 0;}#sk-container-id-5 div.sk-toggleable {background-color: white;}#sk-container-id-5 label.sk-toggleable__label {cursor: pointer;display: block;width: 100%;margin-bottom: 0;padding: 0.3em;box-sizing: border-box;text-align: center;}#sk-container-id-5 label.sk-toggleable__label-arrow:before {content: \"▸\";float: left;margin-right: 0.25em;color: #696969;}#sk-container-id-5 label.sk-toggleable__label-arrow:hover:before {color: black;}#sk-container-id-5 div.sk-estimator:hover label.sk-toggleable__label-arrow:before {color: black;}#sk-container-id-5 div.sk-toggleable__content {max-height: 0;max-width: 0;overflow: hidden;text-align: left;background-color: #f0f8ff;}#sk-container-id-5 div.sk-toggleable__content pre {margin: 0.2em;color: black;border-radius: 0.25em;background-color: #f0f8ff;}#sk-container-id-5 input.sk-toggleable__control:checked~div.sk-toggleable__content {max-height: 200px;max-width: 100%;overflow: auto;}#sk-container-id-5 input.sk-toggleable__control:checked~label.sk-toggleable__label-arrow:before {content: \"▾\";}#sk-container-id-5 div.sk-estimator input.sk-toggleable__control:checked~label.sk-toggleable__label {background-color: #d4ebff;}#sk-container-id-5 div.sk-label input.sk-toggleable__control:checked~label.sk-toggleable__label {background-color: #d4ebff;}#sk-container-id-5 input.sk-hidden--visually {border: 0;clip: rect(1px 1px 1px 1px);clip: rect(1px, 1px, 1px, 1px);height: 1px;margin: -1px;overflow: hidden;padding: 0;position: absolute;width: 1px;}#sk-container-id-5 div.sk-estimator {font-family: monospace;background-color: #f0f8ff;border: 1px dotted black;border-radius: 0.25em;box-sizing: border-box;margin-bottom: 0.5em;}#sk-container-id-5 div.sk-estimator:hover {background-color: #d4ebff;}#sk-container-id-5 div.sk-parallel-item::after {content: \"\";width: 100%;border-bottom: 1px solid gray;flex-grow: 1;}#sk-container-id-5 div.sk-label:hover label.sk-toggleable__label {background-color: #d4ebff;}#sk-container-id-5 div.sk-serial::before {content: \"\";position: absolute;border-left: 1px solid gray;box-sizing: border-box;top: 0;bottom: 0;left: 50%;z-index: 0;}#sk-container-id-5 div.sk-serial {display: flex;flex-direction: column;align-items: center;background-color: white;padding-right: 0.2em;padding-left: 0.2em;position: relative;}#sk-container-id-5 div.sk-item {position: relative;z-index: 1;}#sk-container-id-5 div.sk-parallel {display: flex;align-items: stretch;justify-content: center;background-color: white;position: relative;}#sk-container-id-5 div.sk-item::before, #sk-container-id-5 div.sk-parallel-item::before {content: \"\";position: absolute;border-left: 1px solid gray;box-sizing: border-box;top: 0;bottom: 0;left: 50%;z-index: -1;}#sk-container-id-5 div.sk-parallel-item {display: flex;flex-direction: column;z-index: 1;position: relative;background-color: white;}#sk-container-id-5 div.sk-parallel-item:first-child::after {align-self: flex-end;width: 50%;}#sk-container-id-5 div.sk-parallel-item:last-child::after {align-self: flex-start;width: 50%;}#sk-container-id-5 div.sk-parallel-item:only-child::after {width: 0;}#sk-container-id-5 div.sk-dashed-wrapped {border: 1px dashed gray;margin: 0 0.4em 0.5em 0.4em;box-sizing: border-box;padding-bottom: 0.4em;background-color: white;}#sk-container-id-5 div.sk-label label {font-family: monospace;font-weight: bold;display: inline-block;line-height: 1.2em;}#sk-container-id-5 div.sk-label-container {text-align: center;}#sk-container-id-5 div.sk-container {/* jupyter's `normalize.less` sets `[hidden] { display: none; }` but bootstrap.min.css set `[hidden] { display: none !important; }` so we also need the `!important` here to be able to override the default hidden behavior on the sphinx rendered scikit-learn.org. See: https://github.com/scikit-learn/scikit-learn/issues/21755 */display: inline-block !important;position: relative;}#sk-container-id-5 div.sk-text-repr-fallback {display: none;}</style><div id=\"sk-container-id-5\" class=\"sk-top-container\"><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 sk-toggleable\"><input class=\"sk-toggleable__control sk-hidden--visually\" id=\"sk-estimator-id-5\" type=\"checkbox\" checked><label for=\"sk-estimator-id-5\" class=\"sk-toggleable__label sk-toggleable__label-arrow\">KNeighborsClassifier</label><div class=\"sk-toggleable__content\"><pre>KNeighborsClassifier()</pre></div></div></div></div></div>"},"metadata":{}}]},{"cell_type":"code","source":"y_pred = knn.predict(X_test_trf)","metadata":{"execution":{"iopub.status.busy":"2024-03-30T18:48:41.358189Z","iopub.execute_input":"2024-03-30T18:48:41.361179Z","iopub.status.idle":"2024-03-30T18:48:43.79013Z","shell.execute_reply.started":"2024-03-30T18:48:41.361125Z","shell.execute_reply":"2024-03-30T18:48:43.789157Z"},"trusted":true},"execution_count":60,"outputs":[]},{"cell_type":"code","source":"accuracy_score(y_test,y_pred)","metadata":{"execution":{"iopub.status.busy":"2024-03-30T18:48:43.791224Z","iopub.execute_input":"2024-03-30T18:48:43.791552Z","iopub.status.idle":"2024-03-30T18:48:43.80242Z","shell.execute_reply.started":"2024-03-30T18:48:43.791522Z","shell.execute_reply":"2024-03-30T18:48:43.801407Z"},"trusted":true},"execution_count":61,"outputs":[{"execution_count":61,"output_type":"execute_result","data":{"text/plain":"0.95"},"metadata":{}}]},{"cell_type":"code","source":"for i in range(1,785):\n    pca = PCA(n_components=i)\n    X_train_trf = pca.fit_transform(X_train)\n    X_test_trf = pca.transform(X_test)\n    \n    knn = KNeighborsClassifier()\n    \n    knn.fit(X_train_trf,y_train)\n    \n    y_pred = knn.predict(X_test_trf)\n    \n    print(accuracy_score(y_test,y_pred))","metadata":{"execution":{"iopub.status.busy":"2024-03-30T18:48:43.803741Z","iopub.execute_input":"2024-03-30T18:48:43.804542Z"},"trusted":true},"execution_count":null,"outputs":[{"name":"stdout","text":"0.25726190476190475\n0.3233333333333333\n0.5105952380952381\n0.6660714285714285\n0.738452380952381\n0.8223809523809524\n0.8433333333333334\n0.871904761904762\n0.8873809523809524\n0.9058333333333334\n0.9114285714285715\n0.9180952380952381\n0.9280952380952381\n0.934404761904762\n0.9380952380952381\n0.9371428571428572\n0.9407142857142857\n0.9402380952380952\n0.9430952380952381\n0.9441666666666667\n0.9442857142857143\n0.9452380952380952\n0.9453571428571429\n0.9457142857142857\n0.9485714285714286\n0.9471428571428572\n0.9479761904761905\n0.9470238095238095\n0.949047619047619\n0.9502380952380952\n0.9484523809523809\n0.9521428571428572\n0.950952380952381\n0.950952380952381\n0.9511904761904761\n0.9520238095238095\n0.9510714285714286\n0.9525\n0.9530952380952381\n0.9526190476190476\n0.9532142857142857\n0.9521428571428572\n0.9523809523809523\n0.9541666666666667\n0.9530952380952381\n0.9534523809523809\n0.9541666666666667\n0.9530952380952381\n0.9541666666666667\n0.9527380952380953\n0.9538095238095238\n0.954047619047619\n0.9535714285714286\n0.9547619047619048\n0.9535714285714286\n0.9544047619047619\n0.954047619047619\n0.954047619047619\n0.9542857142857143\n0.9538095238095238\n0.9541666666666667\n0.9542857142857143\n0.9545238095238096\n0.9551190476190476\n0.9551190476190476\n0.9546428571428571\n0.9541666666666667\n0.9548809523809524\n0.9541666666666667\n0.9552380952380952\n0.9541666666666667\n0.9541666666666667\n0.9544047619047619\n0.9548809523809524\n0.9544047619047619\n0.9548809523809524\n0.954047619047619\n0.9541666666666667\n0.955952380952381\n0.9547619047619048\n0.9533333333333334\n0.9546428571428571\n0.9544047619047619\n0.9554761904761905\n0.9546428571428571\n0.9548809523809524\n0.9548809523809524\n0.9544047619047619\n0.9542857142857143\n0.9546428571428571\n0.9547619047619048\n0.9552380952380952\n0.9545238095238096\n0.9546428571428571\n0.9541666666666667\n0.9546428571428571\n0.9539285714285715\n0.954047619047619\n0.9545238095238096\n0.954047619047619\n0.9536904761904762\n0.954047619047619\n0.9536904761904762\n0.9533333333333334\n0.9533333333333334\n0.9539285714285715\n0.9544047619047619\n0.9533333333333334\n0.9534523809523809\n0.9542857142857143\n0.9532142857142857\n0.9536904761904762\n0.9539285714285715\n0.9529761904761904\n0.9542857142857143\n0.9546428571428571\n0.9532142857142857\n0.9533333333333334\n0.9530952380952381\n0.9527380952380953\n0.9529761904761904\n0.9523809523809523\n0.9525\n0.9527380952380953\n0.9536904761904762\n0.9535714285714286\n0.9525\n0.9522619047619048\n0.9526190476190476\n0.9525\n0.9520238095238095\n0.9536904761904762\n0.9525\n0.9527380952380953\n0.9526190476190476\n0.9527380952380953\n0.9522619047619048\n0.9532142857142857\n0.9525\n0.9519047619047619\n0.9526190476190476\n0.9519047619047619\n0.9514285714285714\n0.9532142857142857\n0.9526190476190476\n0.950595238095238\n0.9520238095238095\n0.9526190476190476\n0.9519047619047619\n0.9522619047619048\n0.9515476190476191\n0.950952380952381\n0.9519047619047619\n0.9517857142857142\n0.950952380952381\n0.9520238095238095\n0.9520238095238095\n0.9516666666666667\n0.9517857142857142\n0.9528571428571428\n0.9503571428571429\n0.9513095238095238\n0.9519047619047619\n0.9514285714285714\n0.9519047619047619\n0.9513095238095238\n0.9511904761904761\n0.950595238095238\n0.9510714285714286\n0.9513095238095238\n0.9511904761904761\n0.9503571428571429\n0.9513095238095238\n0.950595238095238\n0.9511904761904761\n0.9510714285714286\n0.9511904761904761\n0.9519047619047619\n0.9508333333333333\n0.9513095238095238\n0.9503571428571429\n0.950952380952381\n0.9508333333333333\n0.9514285714285714\n0.950952380952381\n0.9513095238095238\n0.9514285714285714\n0.9507142857142857\n0.9504761904761905\n0.9514285714285714\n0.9510714285714286\n0.9515476190476191\n0.9510714285714286\n0.950595238095238\n0.9511904761904761\n0.9501190476190476\n0.9507142857142857\n0.9504761904761905\n0.95\n0.9508333333333333\n0.9501190476190476\n0.9495238095238095\n0.9503571428571429\n0.9502380952380952\n0.9507142857142857\n0.9502380952380952\n0.9507142857142857\n0.9503571428571429\n0.95\n0.9508333333333333\n0.9502380952380952\n0.9498809523809524\n0.9504761904761905\n0.9498809523809524\n0.9495238095238095\n0.9494047619047619\n0.9498809523809524\n0.950595238095238\n0.9496428571428571\n0.9489285714285715\n0.9501190476190476\n0.9501190476190476\n0.9495238095238095\n0.9497619047619048\n0.949047619047619\n0.9489285714285715\n0.9491666666666667\n0.9494047619047619\n0.9483333333333334\n0.949047619047619\n0.9497619047619048\n0.9484523809523809\n0.9492857142857143\n0.949047619047619\n0.9485714285714286\n0.9489285714285715\n0.9483333333333334\n0.9485714285714286\n0.9479761904761905\n0.9485714285714286\n0.9484523809523809\n0.9489285714285715\n0.9477380952380953\n0.9494047619047619\n0.9486904761904762\n0.9482142857142857\n0.9485714285714286\n0.9482142857142857\n0.9484523809523809\n0.9475\n0.9480952380952381\n0.9486904761904762\n0.9478571428571428\n0.9489285714285715\n0.9479761904761905\n0.9480952380952381\n0.9473809523809524\n0.9482142857142857\n0.9478571428571428\n0.9476190476190476\n0.9473809523809524\n0.9470238095238095\n0.9475\n0.9470238095238095\n0.9475\n0.9471428571428572\n0.9466666666666667\n0.9471428571428572\n0.9471428571428572\n0.9472619047619047\n0.9472619047619047\n0.9476190476190476\n0.9469047619047619\n0.9469047619047619\n0.9471428571428572\n0.9470238095238095\n0.9472619047619047\n0.9472619047619047\n0.9466666666666667\n0.9465476190476191\n0.9473809523809524\n0.9465476190476191\n0.9466666666666667\n0.9476190476190476\n0.9470238095238095\n0.9466666666666667\n0.9467857142857142\n0.9471428571428572\n","output_type":"stream"}]},{"cell_type":"code","source":"# transforming to a 2D coordinate system\npca = PCA(n_components=2)\nX_train_trf = pca.fit_transform(X_train)\nX_test_trf = pca.transform(X_test)","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"X_train_trf","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import plotly.express as px\ny_train_trf = y_train.astype(str)\nfig = px.scatter(x=X_train_trf[:,0],\n                 y=X_train_trf[:,1],\n                 color=y_train_trf,\n                 color_discrete_sequence=px.colors.qualitative.G10\n                )\nfig.show()","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# transforming in 3D\npca = PCA(n_components=3)\nX_train_trf = pca.fit_transform(X_train)\nX_test_trf = pca.transform(X_test)","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"X_train_trf","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import plotly.express as px\ny_train_trf = y_train.astype(str)\nfig = px.scatter_3d(df, x=X_train_trf[:,0], y=X_train_trf[:,1], z=X_train_trf[:,2],\n              color=y_train_trf)\nfig.update_layout(\n    margin=dict(l=20, r=20, t=20, b=20),\n    paper_bgcolor=\"LightSteelBlue\",\n)\nfig.show()","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"pca.explained_variance_\n# Eigen values","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"pca.components_.shape\n# Eigen vectors","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"pca.explained_variance_ratio_","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"pca = PCA(n_components=None)\nX_train_trf = pca.fit_transform(X_train)\nX_test_trf = pca.transform(X_test)","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"pca.explained_variance_.shape","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"pca.components_.shape","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"np.cumsum(pca.explained_variance_ratio_)","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"plt.plot(np.cumsum(pca.explained_variance_ratio_))","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]}]}