This commit is contained in:
2025-02-07 17:32:41 +01:00
parent bef64b5eb6
commit 070892c551

View File

@@ -62,8 +62,8 @@
"cell_type": "code",
"metadata": {
"ExecuteTime": {
"end_time": "2025-02-06T12:09:35.663428Z",
"start_time": "2025-02-06T12:09:35.519995Z"
"end_time": "2025-02-07T16:32:17.846897Z",
"start_time": "2025-02-07T16:32:17.807782Z"
}
},
"source": "import numpy as np",
@@ -73,8 +73,8 @@
{
"metadata": {
"ExecuteTime": {
"end_time": "2025-02-06T12:09:37.572928Z",
"start_time": "2025-02-06T12:09:37.564513Z"
"end_time": "2025-02-07T16:32:17.854652Z",
"start_time": "2025-02-07T16:32:17.851755Z"
}
},
"cell_type": "code",
@@ -167,8 +167,8 @@
"cell_type": "code",
"metadata": {
"ExecuteTime": {
"end_time": "2025-02-06T12:09:42.269248Z",
"start_time": "2025-02-06T12:09:38.868809Z"
"end_time": "2025-02-07T16:32:18.557770Z",
"start_time": "2025-02-07T16:32:17.940064Z"
}
},
"source": [
@@ -192,8 +192,8 @@
"cell_type": "code",
"metadata": {
"ExecuteTime": {
"end_time": "2025-02-06T12:09:42.277413Z",
"start_time": "2025-02-06T12:09:42.274981Z"
"end_time": "2025-02-07T16:32:18.569068Z",
"start_time": "2025-02-07T16:32:18.566479Z"
}
},
"source": [
@@ -224,8 +224,8 @@
"cell_type": "code",
"metadata": {
"ExecuteTime": {
"end_time": "2025-02-06T12:09:42.553805Z",
"start_time": "2025-02-06T12:09:42.292116Z"
"end_time": "2025-02-07T16:32:18.644913Z",
"start_time": "2025-02-07T16:32:18.609906Z"
}
},
"source": [
@@ -249,8 +249,8 @@
"cell_type": "code",
"metadata": {
"ExecuteTime": {
"end_time": "2025-02-06T12:09:42.568515Z",
"start_time": "2025-02-06T12:09:42.564885Z"
"end_time": "2025-02-07T16:32:18.656592Z",
"start_time": "2025-02-07T16:32:18.654009Z"
}
},
"source": [
@@ -294,8 +294,8 @@
"cell_type": "code",
"metadata": {
"ExecuteTime": {
"end_time": "2025-02-06T12:09:42.583044Z",
"start_time": "2025-02-06T12:09:42.580874Z"
"end_time": "2025-02-07T16:32:18.668040Z",
"start_time": "2025-02-07T16:32:18.666273Z"
}
},
"source": [
@@ -329,8 +329,8 @@
"cell_type": "code",
"metadata": {
"ExecuteTime": {
"end_time": "2025-02-06T12:09:42.607360Z",
"start_time": "2025-02-06T12:09:42.604540Z"
"end_time": "2025-02-07T16:32:18.698079Z",
"start_time": "2025-02-07T16:32:18.695117Z"
}
},
"source": [
@@ -371,8 +371,8 @@
"cell_type": "code",
"metadata": {
"ExecuteTime": {
"end_time": "2025-02-06T12:09:43.571841Z",
"start_time": "2025-02-06T12:09:43.569070Z"
"end_time": "2025-02-07T16:32:18.727024Z",
"start_time": "2025-02-07T16:32:18.725108Z"
}
},
"source": [
@@ -415,8 +415,8 @@
"cell_type": "code",
"metadata": {
"ExecuteTime": {
"end_time": "2025-02-06T12:09:49.298170Z",
"start_time": "2025-02-06T12:09:49.292521Z"
"end_time": "2025-02-07T16:32:18.747162Z",
"start_time": "2025-02-07T16:32:18.743867Z"
}
},
"source": [
@@ -442,8 +442,8 @@
"cell_type": "code",
"metadata": {
"ExecuteTime": {
"end_time": "2025-02-06T12:09:49.680539Z",
"start_time": "2025-02-06T12:09:49.676064Z"
"end_time": "2025-02-07T16:32:18.803162Z",
"start_time": "2025-02-07T16:32:18.798675Z"
}
},
"source": [
@@ -467,8 +467,8 @@
"cell_type": "code",
"metadata": {
"ExecuteTime": {
"end_time": "2025-02-06T12:09:49.895044Z",
"start_time": "2025-02-06T12:09:49.889807Z"
"end_time": "2025-02-07T16:32:18.862775Z",
"start_time": "2025-02-07T16:32:18.859640Z"
}
},
"source": [
@@ -492,8 +492,8 @@
"cell_type": "code",
"metadata": {
"ExecuteTime": {
"end_time": "2025-02-06T12:09:50.047326Z",
"start_time": "2025-02-06T12:09:50.045038Z"
"end_time": "2025-02-07T16:32:18.936458Z",
"start_time": "2025-02-07T16:32:18.932745Z"
}
},
"source": [
@@ -525,8 +525,8 @@
"cell_type": "code",
"metadata": {
"ExecuteTime": {
"end_time": "2025-02-06T12:09:51.499493Z",
"start_time": "2025-02-06T12:09:51.496079Z"
"end_time": "2025-02-07T16:32:18.973366Z",
"start_time": "2025-02-07T16:32:18.970454Z"
}
},
"source": [
@@ -555,8 +555,8 @@
"cell_type": "code",
"metadata": {
"ExecuteTime": {
"end_time": "2025-02-06T12:09:51.964030Z",
"start_time": "2025-02-06T12:09:51.959665Z"
"end_time": "2025-02-07T16:32:19.006689Z",
"start_time": "2025-02-07T16:32:19.003910Z"
}
},
"source": "b.sum(axis=0), b.sum(axis=1), b.sum(axis=2), b.sum()",
@@ -601,8 +601,8 @@
"cell_type": "code",
"metadata": {
"ExecuteTime": {
"end_time": "2025-02-06T12:09:54.092285Z",
"start_time": "2025-02-06T12:09:54.089316Z"
"end_time": "2025-02-07T16:32:19.039310Z",
"start_time": "2025-02-07T16:32:19.037538Z"
}
},
"source": [
@@ -635,8 +635,8 @@
"cell_type": "code",
"metadata": {
"ExecuteTime": {
"end_time": "2025-02-06T12:10:31.335918Z",
"start_time": "2025-02-06T12:10:31.332196Z"
"end_time": "2025-02-07T16:32:19.076151Z",
"start_time": "2025-02-07T16:32:19.073174Z"
}
},
"source": [
@@ -646,19 +646,8 @@
" k_neighbors = np.argsort(distances)[:K]\n",
" return Counter(y_train[k_neighbors]).most_common()[0][0]"
],
"outputs": [
{
"data": {
"text/plain": [
"np.int64(1)"
]
},
"execution_count": 18,
"metadata": {},
"output_type": "execute_result"
}
],
"execution_count": 18
"outputs": [],
"execution_count": 17
},
{
"cell_type": "markdown",
@@ -678,8 +667,8 @@
"cell_type": "code",
"metadata": {
"ExecuteTime": {
"end_time": "2025-02-05T11:26:15.309422Z",
"start_time": "2025-02-05T11:26:15.304219Z"
"end_time": "2025-02-07T16:32:19.114434Z",
"start_time": "2025-02-07T16:32:19.109526Z"
}
},
"source": [
@@ -699,7 +688,7 @@
]
}
],
"execution_count": 175
"execution_count": 18
},
{
"cell_type": "markdown",
@@ -719,8 +708,8 @@
"cell_type": "code",
"metadata": {
"ExecuteTime": {
"end_time": "2025-02-05T11:26:15.657315Z",
"start_time": "2025-02-05T11:26:15.655386Z"
"end_time": "2025-02-07T16:32:19.215397Z",
"start_time": "2025-02-07T16:32:19.148514Z"
}
},
"source": [
@@ -729,7 +718,7 @@
"knn_classifier_2 = KNeighborsClassifier(n_neighbors=3)"
],
"outputs": [],
"execution_count": 176
"execution_count": 19
},
{
"cell_type": "markdown",
@@ -742,8 +731,8 @@
"cell_type": "code",
"metadata": {
"ExecuteTime": {
"end_time": "2025-02-05T11:26:16.224590Z",
"start_time": "2025-02-05T11:26:16.219083Z"
"end_time": "2025-02-07T16:32:19.233667Z",
"start_time": "2025-02-07T16:32:19.227889Z"
}
},
"source": "knn_classifier_2.fit(X_train, y_train)",
@@ -754,7 +743,7 @@
"KNeighborsClassifier(n_neighbors=3)"
],
"text/html": [
"<style>#sk-container-id-4 {\n",
"<style>#sk-container-id-1 {\n",
" /* Definition of color scheme common for light and dark mode */\n",
" --sklearn-color-text: #000;\n",
" --sklearn-color-text-muted: #666;\n",
@@ -785,15 +774,15 @@
" }\n",
"}\n",
"\n",
"#sk-container-id-4 {\n",
"#sk-container-id-1 {\n",
" color: var(--sklearn-color-text);\n",
"}\n",
"\n",
"#sk-container-id-4 pre {\n",
"#sk-container-id-1 pre {\n",
" padding: 0;\n",
"}\n",
"\n",
"#sk-container-id-4 input.sk-hidden--visually {\n",
"#sk-container-id-1 input.sk-hidden--visually {\n",
" border: 0;\n",
" clip: rect(1px 1px 1px 1px);\n",
" clip: rect(1px, 1px, 1px, 1px);\n",
@@ -805,7 +794,7 @@
" width: 1px;\n",
"}\n",
"\n",
"#sk-container-id-4 div.sk-dashed-wrapped {\n",
"#sk-container-id-1 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",
@@ -813,7 +802,7 @@
" background-color: var(--sklearn-color-background);\n",
"}\n",
"\n",
"#sk-container-id-4 div.sk-container {\n",
"#sk-container-id-1 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",
@@ -823,7 +812,7 @@
" position: relative;\n",
"}\n",
"\n",
"#sk-container-id-4 div.sk-text-repr-fallback {\n",
"#sk-container-id-1 div.sk-text-repr-fallback {\n",
" display: none;\n",
"}\n",
"\n",
@@ -839,14 +828,14 @@
"\n",
"/* Parallel-specific style estimator block */\n",
"\n",
"#sk-container-id-4 div.sk-parallel-item::after {\n",
"#sk-container-id-1 div.sk-parallel-item::after {\n",
" content: \"\";\n",
" width: 100%;\n",
" border-bottom: 2px solid var(--sklearn-color-text-on-default-background);\n",
" flex-grow: 1;\n",
"}\n",
"\n",
"#sk-container-id-4 div.sk-parallel {\n",
"#sk-container-id-1 div.sk-parallel {\n",
" display: flex;\n",
" align-items: stretch;\n",
" justify-content: center;\n",
@@ -854,28 +843,28 @@
" position: relative;\n",
"}\n",
"\n",
"#sk-container-id-4 div.sk-parallel-item {\n",
"#sk-container-id-1 div.sk-parallel-item {\n",
" display: flex;\n",
" flex-direction: column;\n",
"}\n",
"\n",
"#sk-container-id-4 div.sk-parallel-item:first-child::after {\n",
"#sk-container-id-1 div.sk-parallel-item:first-child::after {\n",
" align-self: flex-end;\n",
" width: 50%;\n",
"}\n",
"\n",
"#sk-container-id-4 div.sk-parallel-item:last-child::after {\n",
"#sk-container-id-1 div.sk-parallel-item:last-child::after {\n",
" align-self: flex-start;\n",
" width: 50%;\n",
"}\n",
"\n",
"#sk-container-id-4 div.sk-parallel-item:only-child::after {\n",
"#sk-container-id-1 div.sk-parallel-item:only-child::after {\n",
" width: 0;\n",
"}\n",
"\n",
"/* Serial-specific style estimator block */\n",
"\n",
"#sk-container-id-4 div.sk-serial {\n",
"#sk-container-id-1 div.sk-serial {\n",
" display: flex;\n",
" flex-direction: column;\n",
" align-items: center;\n",
@@ -893,14 +882,14 @@
"\n",
"/* Pipeline and ColumnTransformer style (default) */\n",
"\n",
"#sk-container-id-4 div.sk-toggleable {\n",
"#sk-container-id-1 div.sk-toggleable {\n",
" /* Default theme specific background. It is overwritten whether we have a\n",
" specific estimator or a Pipeline/ColumnTransformer */\n",
" background-color: var(--sklearn-color-background);\n",
"}\n",
"\n",
"/* Toggleable label */\n",
"#sk-container-id-4 label.sk-toggleable__label {\n",
"#sk-container-id-1 label.sk-toggleable__label {\n",
" cursor: pointer;\n",
" display: flex;\n",
" width: 100%;\n",
@@ -913,13 +902,13 @@
" gap: 0.5em;\n",
"}\n",
"\n",
"#sk-container-id-4 label.sk-toggleable__label .caption {\n",
"#sk-container-id-1 label.sk-toggleable__label .caption {\n",
" font-size: 0.6rem;\n",
" font-weight: lighter;\n",
" color: var(--sklearn-color-text-muted);\n",
"}\n",
"\n",
"#sk-container-id-4 label.sk-toggleable__label-arrow:before {\n",
"#sk-container-id-1 label.sk-toggleable__label-arrow:before {\n",
" /* Arrow on the left of the label */\n",
" content: \"▸\";\n",
" float: left;\n",
@@ -927,13 +916,13 @@
" color: var(--sklearn-color-icon);\n",
"}\n",
"\n",
"#sk-container-id-4 label.sk-toggleable__label-arrow:hover:before {\n",
"#sk-container-id-1 label.sk-toggleable__label-arrow:hover:before {\n",
" color: var(--sklearn-color-text);\n",
"}\n",
"\n",
"/* Toggleable content - dropdown */\n",
"\n",
"#sk-container-id-4 div.sk-toggleable__content {\n",
"#sk-container-id-1 div.sk-toggleable__content {\n",
" max-height: 0;\n",
" max-width: 0;\n",
" overflow: hidden;\n",
@@ -942,12 +931,12 @@
" background-color: var(--sklearn-color-unfitted-level-0);\n",
"}\n",
"\n",
"#sk-container-id-4 div.sk-toggleable__content.fitted {\n",
"#sk-container-id-1 div.sk-toggleable__content.fitted {\n",
" /* fitted */\n",
" background-color: var(--sklearn-color-fitted-level-0);\n",
"}\n",
"\n",
"#sk-container-id-4 div.sk-toggleable__content pre {\n",
"#sk-container-id-1 div.sk-toggleable__content pre {\n",
" margin: 0.2em;\n",
" border-radius: 0.25em;\n",
" color: var(--sklearn-color-text);\n",
@@ -955,79 +944,79 @@
" background-color: var(--sklearn-color-unfitted-level-0);\n",
"}\n",
"\n",
"#sk-container-id-4 div.sk-toggleable__content.fitted pre {\n",
"#sk-container-id-1 div.sk-toggleable__content.fitted pre {\n",
" /* unfitted */\n",
" background-color: var(--sklearn-color-fitted-level-0);\n",
"}\n",
"\n",
"#sk-container-id-4 input.sk-toggleable__control:checked~div.sk-toggleable__content {\n",
"#sk-container-id-1 input.sk-toggleable__control:checked~div.sk-toggleable__content {\n",
" /* Expand drop-down */\n",
" max-height: 200px;\n",
" max-width: 100%;\n",
" overflow: auto;\n",
"}\n",
"\n",
"#sk-container-id-4 input.sk-toggleable__control:checked~label.sk-toggleable__label-arrow:before {\n",
"#sk-container-id-1 input.sk-toggleable__control:checked~label.sk-toggleable__label-arrow:before {\n",
" content: \"▾\";\n",
"}\n",
"\n",
"/* Pipeline/ColumnTransformer-specific style */\n",
"\n",
"#sk-container-id-4 div.sk-label input.sk-toggleable__control:checked~label.sk-toggleable__label {\n",
"#sk-container-id-1 div.sk-label input.sk-toggleable__control:checked~label.sk-toggleable__label {\n",
" color: var(--sklearn-color-text);\n",
" background-color: var(--sklearn-color-unfitted-level-2);\n",
"}\n",
"\n",
"#sk-container-id-4 div.sk-label.fitted input.sk-toggleable__control:checked~label.sk-toggleable__label {\n",
"#sk-container-id-1 div.sk-label.fitted input.sk-toggleable__control:checked~label.sk-toggleable__label {\n",
" background-color: var(--sklearn-color-fitted-level-2);\n",
"}\n",
"\n",
"/* Estimator-specific style */\n",
"\n",
"/* Colorize estimator box */\n",
"#sk-container-id-4 div.sk-estimator input.sk-toggleable__control:checked~label.sk-toggleable__label {\n",
"#sk-container-id-1 div.sk-estimator input.sk-toggleable__control:checked~label.sk-toggleable__label {\n",
" /* unfitted */\n",
" background-color: var(--sklearn-color-unfitted-level-2);\n",
"}\n",
"\n",
"#sk-container-id-4 div.sk-estimator.fitted input.sk-toggleable__control:checked~label.sk-toggleable__label {\n",
"#sk-container-id-1 div.sk-estimator.fitted input.sk-toggleable__control:checked~label.sk-toggleable__label {\n",
" /* fitted */\n",
" background-color: var(--sklearn-color-fitted-level-2);\n",
"}\n",
"\n",
"#sk-container-id-4 div.sk-label label.sk-toggleable__label,\n",
"#sk-container-id-4 div.sk-label label {\n",
"#sk-container-id-1 div.sk-label label.sk-toggleable__label,\n",
"#sk-container-id-1 div.sk-label label {\n",
" /* The background is the default theme color */\n",
" color: var(--sklearn-color-text-on-default-background);\n",
"}\n",
"\n",
"/* On hover, darken the color of the background */\n",
"#sk-container-id-4 div.sk-label:hover label.sk-toggleable__label {\n",
"#sk-container-id-1 div.sk-label:hover label.sk-toggleable__label {\n",
" color: var(--sklearn-color-text);\n",
" background-color: var(--sklearn-color-unfitted-level-2);\n",
"}\n",
"\n",
"/* Label box, darken color on hover, fitted */\n",
"#sk-container-id-4 div.sk-label.fitted:hover label.sk-toggleable__label.fitted {\n",
"#sk-container-id-1 div.sk-label.fitted:hover label.sk-toggleable__label.fitted {\n",
" color: var(--sklearn-color-text);\n",
" background-color: var(--sklearn-color-fitted-level-2);\n",
"}\n",
"\n",
"/* Estimator label */\n",
"\n",
"#sk-container-id-4 div.sk-label label {\n",
"#sk-container-id-1 div.sk-label label {\n",
" font-family: monospace;\n",
" font-weight: bold;\n",
" display: inline-block;\n",
" line-height: 1.2em;\n",
"}\n",
"\n",
"#sk-container-id-4 div.sk-label-container {\n",
"#sk-container-id-1 div.sk-label-container {\n",
" text-align: center;\n",
"}\n",
"\n",
"/* Estimator-specific */\n",
"#sk-container-id-4 div.sk-estimator {\n",
"#sk-container-id-1 div.sk-estimator {\n",
" font-family: monospace;\n",
" border: 1px dotted var(--sklearn-color-border-box);\n",
" border-radius: 0.25em;\n",
@@ -1037,18 +1026,18 @@
" background-color: var(--sklearn-color-unfitted-level-0);\n",
"}\n",
"\n",
"#sk-container-id-4 div.sk-estimator.fitted {\n",
"#sk-container-id-1 div.sk-estimator.fitted {\n",
" /* fitted */\n",
" background-color: var(--sklearn-color-fitted-level-0);\n",
"}\n",
"\n",
"/* on hover */\n",
"#sk-container-id-4 div.sk-estimator:hover {\n",
"#sk-container-id-1 div.sk-estimator:hover {\n",
" /* unfitted */\n",
" background-color: var(--sklearn-color-unfitted-level-2);\n",
"}\n",
"\n",
"#sk-container-id-4 div.sk-estimator.fitted:hover {\n",
"#sk-container-id-1 div.sk-estimator.fitted:hover {\n",
" /* fitted */\n",
" background-color: var(--sklearn-color-fitted-level-2);\n",
"}\n",
@@ -1136,7 +1125,7 @@
"\n",
"/* \"?\"-specific style due to the `<a>` HTML tag */\n",
"\n",
"#sk-container-id-4 a.estimator_doc_link {\n",
"#sk-container-id-1 a.estimator_doc_link {\n",
" float: right;\n",
" font-size: 1rem;\n",
" line-height: 1em;\n",
@@ -1151,33 +1140,33 @@
" border: var(--sklearn-color-unfitted-level-1) 1pt solid;\n",
"}\n",
"\n",
"#sk-container-id-4 a.estimator_doc_link.fitted {\n",
"#sk-container-id-1 a.estimator_doc_link.fitted {\n",
" /* fitted */\n",
" border: var(--sklearn-color-fitted-level-1) 1pt solid;\n",
" color: var(--sklearn-color-fitted-level-1);\n",
"}\n",
"\n",
"/* On hover */\n",
"#sk-container-id-4 a.estimator_doc_link:hover {\n",
"#sk-container-id-1 a.estimator_doc_link:hover {\n",
" /* unfitted */\n",
" background-color: var(--sklearn-color-unfitted-level-3);\n",
" color: var(--sklearn-color-background);\n",
" text-decoration: none;\n",
"}\n",
"\n",
"#sk-container-id-4 a.estimator_doc_link.fitted:hover {\n",
"#sk-container-id-1 a.estimator_doc_link.fitted:hover {\n",
" /* fitted */\n",
" background-color: var(--sklearn-color-fitted-level-3);\n",
"}\n",
"</style><div id=\"sk-container-id-4\" class=\"sk-top-container\"><div class=\"sk-text-repr-fallback\"><pre>KNeighborsClassifier(n_neighbors=3)</pre><b>In a Jupyter environment, please rerun this cell to show the HTML representation or trust the notebook. <br />On GitHub, the HTML representation is unable to render, please try loading this page with nbviewer.org.</b></div><div class=\"sk-container\" hidden><div class=\"sk-item\"><div class=\"sk-estimator fitted sk-toggleable\"><input class=\"sk-toggleable__control sk-hidden--visually\" id=\"sk-estimator-id-4\" type=\"checkbox\" checked><label for=\"sk-estimator-id-4\" 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.6/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\"><pre>KNeighborsClassifier(n_neighbors=3)</pre></div> </div></div></div></div>"
"</style><div id=\"sk-container-id-1\" class=\"sk-top-container\"><div class=\"sk-text-repr-fallback\"><pre>KNeighborsClassifier(n_neighbors=3)</pre><b>In a Jupyter environment, please rerun this cell to show the HTML representation or trust the notebook. <br />On GitHub, the HTML representation is unable to render, please try loading this page with nbviewer.org.</b></div><div class=\"sk-container\" hidden><div class=\"sk-item\"><div class=\"sk-estimator fitted sk-toggleable\"><input class=\"sk-toggleable__control sk-hidden--visually\" id=\"sk-estimator-id-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.6/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\"><pre>KNeighborsClassifier(n_neighbors=3)</pre></div> </div></div></div></div>"
]
},
"execution_count": 177,
"execution_count": 20,
"metadata": {},
"output_type": "execute_result"
}
],
"execution_count": 177
"execution_count": 20
},
{
"cell_type": "markdown",
@@ -1190,8 +1179,8 @@
"cell_type": "code",
"metadata": {
"ExecuteTime": {
"end_time": "2025-02-05T11:26:17.023370Z",
"start_time": "2025-02-05T11:26:17.018037Z"
"end_time": "2025-02-07T16:32:19.260546Z",
"start_time": "2025-02-07T16:32:19.254828Z"
}
},
"source": "knn_classifier_2.score(X_test, y_test)",
@@ -1202,12 +1191,12 @@
"0.98"
]
},
"execution_count": 178,
"execution_count": 21,
"metadata": {},
"output_type": "execute_result"
}
],
"execution_count": 178
"execution_count": 21
},
{
"cell_type": "markdown",
@@ -1255,8 +1244,8 @@
"cell_type": "code",
"metadata": {
"ExecuteTime": {
"end_time": "2025-02-05T11:26:19.505745Z",
"start_time": "2025-02-05T11:26:19.502276Z"
"end_time": "2025-02-07T16:32:19.559521Z",
"start_time": "2025-02-07T16:32:19.282596Z"
}
},
"source": [
@@ -1266,14 +1255,14 @@
"from sklearn.neighbors import KNeighborsClassifier"
],
"outputs": [],
"execution_count": 179
"execution_count": 22
},
{
"cell_type": "code",
"metadata": {
"ExecuteTime": {
"end_time": "2025-02-05T11:26:19.890538Z",
"start_time": "2025-02-05T11:26:19.887279Z"
"end_time": "2025-02-07T16:32:19.575414Z",
"start_time": "2025-02-07T16:32:19.570441Z"
}
},
"source": [
@@ -1297,14 +1286,14 @@
]
}
],
"execution_count": 180
"execution_count": 23
},
{
"cell_type": "code",
"metadata": {
"ExecuteTime": {
"end_time": "2025-02-05T11:26:20.564996Z",
"start_time": "2025-02-05T11:26:20.484918Z"
"end_time": "2025-02-07T16:32:19.693282Z",
"start_time": "2025-02-07T16:32:19.599201Z"
}
},
"source": [
@@ -1315,10 +1304,10 @@
{
"data": {
"text/plain": [
"<matplotlib.collections.PathCollection at 0x10ed75a60>"
"<matplotlib.collections.PathCollection at 0x12546dd60>"
]
},
"execution_count": 181,
"execution_count": 24,
"metadata": {},
"output_type": "execute_result"
},
@@ -1333,7 +1322,7 @@
"output_type": "display_data"
}
],
"execution_count": 181
"execution_count": 24
},
{
"cell_type": "markdown",
@@ -1346,8 +1335,8 @@
"cell_type": "code",
"metadata": {
"ExecuteTime": {
"end_time": "2025-02-05T11:27:09.124075Z",
"start_time": "2025-02-05T11:27:09.119577Z"
"end_time": "2025-02-07T16:32:19.710747Z",
"start_time": "2025-02-07T16:32:19.706881Z"
}
},
"source": [
@@ -1361,7 +1350,7 @@
" KNNs.append(knn_classifier_k)"
],
"outputs": [],
"execution_count": 188
"execution_count": 25
},
{
"cell_type": "markdown",
@@ -1374,8 +1363,8 @@
"cell_type": "code",
"metadata": {
"ExecuteTime": {
"end_time": "2025-02-05T11:26:42.695499Z",
"start_time": "2025-02-05T11:26:41.672308Z"
"end_time": "2025-02-07T16:32:20.615872Z",
"start_time": "2025-02-07T16:32:19.741060Z"
}
},
"source": [
@@ -1396,17 +1385,6 @@
"plt.show()\n"
],
"outputs": [
{
"ename": "IndexError",
"evalue": "index 2 is out of bounds for axis 0 with size 2",
"output_type": "error",
"traceback": [
"\u001B[0;31m---------------------------------------------------------------------------\u001B[0m",
"\u001B[0;31mIndexError\u001B[0m Traceback (most recent call last)",
"Cell \u001B[0;32mIn[187], line 11\u001B[0m\n\u001B[1;32m 8\u001B[0m Z \u001B[38;5;241m=\u001B[39m clf\u001B[38;5;241m.\u001B[39mpredict(np\u001B[38;5;241m.\u001B[39mc_[xx\u001B[38;5;241m.\u001B[39mravel(), yy\u001B[38;5;241m.\u001B[39mravel()])\n\u001B[1;32m 9\u001B[0m Z \u001B[38;5;241m=\u001B[39m Z\u001B[38;5;241m.\u001B[39mreshape(xx\u001B[38;5;241m.\u001B[39mshape)\n\u001B[0;32m---> 11\u001B[0m \u001B[43maxarr\u001B[49m\u001B[43m[\u001B[49m\u001B[43midx\u001B[49m\u001B[43m[\u001B[49m\u001B[38;5;241;43m0\u001B[39;49m\u001B[43m]\u001B[49m\u001B[43m,\u001B[49m\u001B[43m \u001B[49m\u001B[43midx\u001B[49m\u001B[43m[\u001B[49m\u001B[38;5;241;43m1\u001B[39;49m\u001B[43m]\u001B[49m\u001B[43m]\u001B[49m\u001B[38;5;241m.\u001B[39mcontourf(xx, yy, Z, alpha\u001B[38;5;241m=\u001B[39m\u001B[38;5;241m0.4\u001B[39m)\n\u001B[1;32m 12\u001B[0m axarr[idx[\u001B[38;5;241m0\u001B[39m], idx[\u001B[38;5;241m1\u001B[39m]]\u001B[38;5;241m.\u001B[39mscatter(X2[:, \u001B[38;5;241m0\u001B[39m], X2[:, \u001B[38;5;241m1\u001B[39m], c\u001B[38;5;241m=\u001B[39mY2, s\u001B[38;5;241m=\u001B[39m\u001B[38;5;241m20\u001B[39m, edgecolor\u001B[38;5;241m=\u001B[39m\u001B[38;5;124m\"\u001B[39m\u001B[38;5;124mk\u001B[39m\u001B[38;5;124m\"\u001B[39m)\n\u001B[1;32m 13\u001B[0m axarr[idx[\u001B[38;5;241m0\u001B[39m], idx[\u001B[38;5;241m1\u001B[39m]]\u001B[38;5;241m.\u001B[39mset_title(tt)\n",
"\u001B[0;31mIndexError\u001B[0m: index 2 is out of bounds for axis 0 with size 2"
]
},
{
"data": {
"text/plain": [
@@ -1418,7 +1396,7 @@
"output_type": "display_data"
}
],
"execution_count": 187
"execution_count": 26
},
{
"cell_type": "markdown",
@@ -1459,8 +1437,8 @@
"cell_type": "code",
"metadata": {
"ExecuteTime": {
"end_time": "2025-02-05T09:48:21.055727Z",
"start_time": "2025-02-05T09:48:18.802198Z"
"end_time": "2025-02-07T16:32:23.064353Z",
"start_time": "2025-02-07T16:32:20.623241Z"
}
},
"source": [
@@ -1469,7 +1447,7 @@
"mnist = fetch_openml('mnist_784')"
],
"outputs": [],
"execution_count": 52
"execution_count": 27
},
{
"cell_type": "markdown",
@@ -1482,8 +1460,8 @@
"cell_type": "code",
"metadata": {
"ExecuteTime": {
"end_time": "2025-02-05T09:48:22.477736Z",
"start_time": "2025-02-05T09:48:22.465303Z"
"end_time": "2025-02-07T16:32:23.107290Z",
"start_time": "2025-02-07T16:32:23.095904Z"
}
},
"source": [
@@ -1847,19 +1825,19 @@
"</div>"
]
},
"execution_count": 53,
"execution_count": 28,
"metadata": {},
"output_type": "execute_result"
}
],
"execution_count": 53
"execution_count": 28
},
{
"cell_type": "code",
"metadata": {
"ExecuteTime": {
"end_time": "2025-02-05T09:48:23.448971Z",
"start_time": "2025-02-05T09:48:23.445653Z"
"end_time": "2025-02-07T16:32:23.292852Z",
"start_time": "2025-02-07T16:32:23.277441Z"
}
},
"source": [
@@ -1884,31 +1862,31 @@
"Categories (10, object): ['0', '1', '2', '3', ..., '6', '7', '8', '9']"
]
},
"execution_count": 54,
"execution_count": 29,
"metadata": {},
"output_type": "execute_result"
}
],
"execution_count": 54
"execution_count": 29
},
{
"cell_type": "code",
"metadata": {
"ExecuteTime": {
"end_time": "2025-02-05T09:48:24.144564Z",
"start_time": "2025-02-05T09:48:24.142427Z"
"end_time": "2025-02-07T16:32:23.505490Z",
"start_time": "2025-02-07T16:32:23.500486Z"
}
},
"source": "X, y = mnist.data, mnist.target",
"outputs": [],
"execution_count": 55
"execution_count": 30
},
{
"cell_type": "code",
"metadata": {
"ExecuteTime": {
"end_time": "2025-02-05T09:48:24.514332Z",
"start_time": "2025-02-05T09:48:24.511486Z"
"end_time": "2025-02-07T16:32:23.559082Z",
"start_time": "2025-02-07T16:32:23.555630Z"
}
},
"source": [
@@ -1921,19 +1899,19 @@
"pandas.core.frame.DataFrame"
]
},
"execution_count": 56,
"execution_count": 31,
"metadata": {},
"output_type": "execute_result"
}
],
"execution_count": 56
"execution_count": 31
},
{
"cell_type": "code",
"metadata": {
"ExecuteTime": {
"end_time": "2025-02-05T09:48:24.886667Z",
"start_time": "2025-02-05T09:48:24.884478Z"
"end_time": "2025-02-07T16:32:23.690898Z",
"start_time": "2025-02-07T16:32:23.686508Z"
}
},
"source": [
@@ -1946,12 +1924,12 @@
"pandas.core.series.Series"
]
},
"execution_count": 57,
"execution_count": 32,
"metadata": {},
"output_type": "execute_result"
}
],
"execution_count": 57
"execution_count": 32
},
{
"cell_type": "markdown",
@@ -1964,8 +1942,8 @@
"cell_type": "code",
"metadata": {
"ExecuteTime": {
"end_time": "2025-02-05T09:48:31.763896Z",
"start_time": "2025-02-05T09:48:31.760241Z"
"end_time": "2025-02-07T16:32:23.768402Z",
"start_time": "2025-02-07T16:32:23.759338Z"
}
},
"source": [
@@ -1979,19 +1957,19 @@
"(numpy.ndarray, numpy.ndarray)"
]
},
"execution_count": 58,
"execution_count": 33,
"metadata": {},
"output_type": "execute_result"
}
],
"execution_count": 58
"execution_count": 33
},
{
"cell_type": "code",
"metadata": {
"ExecuteTime": {
"end_time": "2025-02-05T09:48:32.298865Z",
"start_time": "2025-02-05T09:48:32.295472Z"
"end_time": "2025-02-07T16:32:23.842258Z",
"start_time": "2025-02-07T16:32:23.831330Z"
}
},
"source": "X.shape, y.shape",
@@ -2002,12 +1980,12 @@
"((70000, 784), (70000,))"
]
},
"execution_count": 59,
"execution_count": 34,
"metadata": {},
"output_type": "execute_result"
}
],
"execution_count": 59
"execution_count": 34
},
{
"cell_type": "markdown",
@@ -2020,8 +1998,8 @@
"cell_type": "code",
"metadata": {
"ExecuteTime": {
"end_time": "2025-02-05T09:48:34.139776Z",
"start_time": "2025-02-05T09:48:34.085344Z"
"end_time": "2025-02-07T16:32:23.969004Z",
"start_time": "2025-02-07T16:32:23.905090Z"
}
},
"source": [
@@ -2043,14 +2021,14 @@
"output_type": "display_data"
}
],
"execution_count": 60
"execution_count": 35
},
{
"cell_type": "code",
"metadata": {
"ExecuteTime": {
"end_time": "2025-02-05T09:48:34.972262Z",
"start_time": "2025-02-05T09:48:34.969534Z"
"end_time": "2025-02-07T16:32:24.460659Z",
"start_time": "2025-02-07T16:32:24.455555Z"
}
},
"source": [
@@ -2064,26 +2042,26 @@
"'5'"
]
},
"execution_count": 61,
"execution_count": 36,
"metadata": {},
"output_type": "execute_result"
}
],
"execution_count": 61
"execution_count": 36
},
{
"cell_type": "code",
"metadata": {
"ExecuteTime": {
"end_time": "2025-02-05T09:48:36.165952Z",
"start_time": "2025-02-05T09:48:35.753636Z"
"end_time": "2025-02-07T16:32:25.246771Z",
"start_time": "2025-02-07T16:32:24.668327Z"
}
},
"source": [
"X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.33, random_state=42)"
],
"outputs": [],
"execution_count": 62
"execution_count": 37
},
{
"cell_type": "markdown",
@@ -2097,9 +2075,11 @@
},
{
"metadata": {
"jupyter": {
"is_executing": true
},
"ExecuteTime": {
"end_time": "2025-02-05T09:55:57.835820Z",
"start_time": "2025-02-05T09:55:02.002908Z"
"start_time": "2025-02-07T16:32:25.251727Z"
}
},
"cell_type": "code",
@@ -2117,19 +2097,9 @@
"text": [
"Accuracy score: 0.9693506493506493\n"
]
},
{
"data": {
"text/plain": [
"'5'"
]
},
"execution_count": 74,
"metadata": {},
"output_type": "execute_result"
}
],
"execution_count": 74
"execution_count": null
},
{
"cell_type": "markdown",
@@ -2408,13 +2378,6 @@
}
],
"execution_count": 93
},
{
"metadata": {},
"cell_type": "code",
"outputs": [],
"execution_count": null,
"source": ""
}
],
"metadata": {