Add tp2 and tp2 bis

This commit is contained in:
2025-02-05 22:08:02 +01:00
parent 767355c4df
commit 82ed0a1d8a
5 changed files with 21547 additions and 124 deletions

View File

@@ -192,8 +192,8 @@
"cell_type": "code",
"metadata": {
"ExecuteTime": {
"end_time": "2025-02-05T10:14:48.428506Z",
"start_time": "2025-02-05T10:14:48.426770Z"
"end_time": "2025-02-05T11:26:08.647762Z",
"start_time": "2025-02-05T11:26:08.645423Z"
}
},
"source": [
@@ -211,7 +211,7 @@
]
}
],
"execution_count": 124
"execution_count": 161
},
{
"cell_type": "markdown",
@@ -224,8 +224,8 @@
"cell_type": "code",
"metadata": {
"ExecuteTime": {
"end_time": "2025-02-05T10:14:48.797654Z",
"start_time": "2025-02-05T10:14:48.795164Z"
"end_time": "2025-02-05T11:26:09.360612Z",
"start_time": "2025-02-05T11:26:09.357969Z"
}
},
"source": [
@@ -234,7 +234,7 @@
"X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.33, random_state=42)"
],
"outputs": [],
"execution_count": 125
"execution_count": 162
},
{
"cell_type": "markdown",
@@ -249,8 +249,8 @@
"cell_type": "code",
"metadata": {
"ExecuteTime": {
"end_time": "2025-02-05T10:14:49.081088Z",
"start_time": "2025-02-05T10:14:49.078343Z"
"end_time": "2025-02-05T11:26:10.135924Z",
"start_time": "2025-02-05T11:26:10.133376Z"
}
},
"source": [
@@ -272,7 +272,7 @@
]
}
],
"execution_count": 126
"execution_count": 163
},
{
"cell_type": "markdown",
@@ -294,8 +294,8 @@
"cell_type": "code",
"metadata": {
"ExecuteTime": {
"end_time": "2025-02-05T10:14:49.601880Z",
"start_time": "2025-02-05T10:14:49.599912Z"
"end_time": "2025-02-05T11:26:10.847708Z",
"start_time": "2025-02-05T11:26:10.845674Z"
}
},
"source": [
@@ -303,7 +303,7 @@
" return np.linalg.norm(sample1 - sample2, axis=1) ** 2"
],
"outputs": [],
"execution_count": 127
"execution_count": 164
},
{
"cell_type": "markdown",
@@ -329,8 +329,8 @@
"cell_type": "code",
"metadata": {
"ExecuteTime": {
"end_time": "2025-02-05T10:14:49.994904Z",
"start_time": "2025-02-05T10:14:49.991965Z"
"end_time": "2025-02-05T11:26:11.319414Z",
"start_time": "2025-02-05T11:26:11.315241Z"
}
},
"source": [
@@ -365,14 +365,14 @@
]
}
],
"execution_count": 128
"execution_count": 165
},
{
"cell_type": "code",
"metadata": {
"ExecuteTime": {
"end_time": "2025-02-05T10:14:50.483302Z",
"start_time": "2025-02-05T10:14:50.481416Z"
"end_time": "2025-02-05T11:26:11.549555Z",
"start_time": "2025-02-05T11:26:11.546889Z"
}
},
"source": [
@@ -385,7 +385,7 @@
" return Counter(y_train[nearest_neighbors]).most_common(1)[0][0]"
],
"outputs": [],
"execution_count": 129
"execution_count": 166
},
{
"cell_type": "markdown",
@@ -415,8 +415,8 @@
"cell_type": "code",
"metadata": {
"ExecuteTime": {
"end_time": "2025-02-05T10:14:51.981600Z",
"start_time": "2025-02-05T10:14:51.978436Z"
"end_time": "2025-02-05T11:26:12.511511Z",
"start_time": "2025-02-05T11:26:12.508445Z"
}
},
"source": [
@@ -431,19 +431,19 @@
" [3, 4]])"
]
},
"execution_count": 130,
"execution_count": 167,
"metadata": {},
"output_type": "execute_result"
}
],
"execution_count": 130
"execution_count": 167
},
{
"cell_type": "code",
"metadata": {
"ExecuteTime": {
"end_time": "2025-02-05T10:14:52.242090Z",
"start_time": "2025-02-05T10:14:52.238352Z"
"end_time": "2025-02-05T11:26:12.784146Z",
"start_time": "2025-02-05T11:26:12.780845Z"
}
},
"source": [
@@ -456,19 +456,19 @@
"np.int64(10)"
]
},
"execution_count": 131,
"execution_count": 168,
"metadata": {},
"output_type": "execute_result"
}
],
"execution_count": 131
"execution_count": 168
},
{
"cell_type": "code",
"metadata": {
"ExecuteTime": {
"end_time": "2025-02-05T10:14:52.528721Z",
"start_time": "2025-02-05T10:14:52.526367Z"
"end_time": "2025-02-05T11:26:13.022841Z",
"start_time": "2025-02-05T11:26:13.020426Z"
}
},
"source": [
@@ -481,19 +481,19 @@
"array([3, 7])"
]
},
"execution_count": 132,
"execution_count": 169,
"metadata": {},
"output_type": "execute_result"
}
],
"execution_count": 132
"execution_count": 169
},
{
"cell_type": "code",
"metadata": {
"ExecuteTime": {
"end_time": "2025-02-05T10:14:52.847083Z",
"start_time": "2025-02-05T10:14:52.844802Z"
"end_time": "2025-02-05T11:26:13.231874Z",
"start_time": "2025-02-05T11:26:13.229410Z"
}
},
"source": [
@@ -506,12 +506,12 @@
"array([4, 6])"
]
},
"execution_count": 133,
"execution_count": 170,
"metadata": {},
"output_type": "execute_result"
}
],
"execution_count": 133
"execution_count": 170
},
{
"cell_type": "markdown",
@@ -525,8 +525,8 @@
"cell_type": "code",
"metadata": {
"ExecuteTime": {
"end_time": "2025-02-05T10:14:53.295062Z",
"start_time": "2025-02-05T10:14:53.292189Z"
"end_time": "2025-02-05T11:26:13.632871Z",
"start_time": "2025-02-05T11:26:13.629716Z"
}
},
"source": [
@@ -544,19 +544,19 @@
" [6, 7]]])"
]
},
"execution_count": 134,
"execution_count": 171,
"metadata": {},
"output_type": "execute_result"
}
],
"execution_count": 134
"execution_count": 171
},
{
"cell_type": "code",
"metadata": {
"ExecuteTime": {
"end_time": "2025-02-05T10:14:53.595339Z",
"start_time": "2025-02-05T10:14:53.592455Z"
"end_time": "2025-02-05T11:26:13.817580Z",
"start_time": "2025-02-05T11:26:13.814914Z"
}
},
"source": "b.sum(axis=0), b.sum(axis=1), b.sum(axis=2), b.sum()",
@@ -573,12 +573,12 @@
" np.int64(28))"
]
},
"execution_count": 135,
"execution_count": 172,
"metadata": {},
"output_type": "execute_result"
}
],
"execution_count": 135
"execution_count": 172
},
{
"cell_type": "markdown",
@@ -601,8 +601,8 @@
"cell_type": "code",
"metadata": {
"ExecuteTime": {
"end_time": "2025-02-05T10:14:54.620927Z",
"start_time": "2025-02-05T10:14:54.617991Z"
"end_time": "2025-02-05T11:26:14.342154Z",
"start_time": "2025-02-05T11:26:14.340114Z"
}
},
"source": [
@@ -611,7 +611,7 @@
" return np.linalg.norm(sample1 - sample2, axis=1) ** 2"
],
"outputs": [],
"execution_count": 136
"execution_count": 173
},
{
"cell_type": "markdown",
@@ -636,8 +636,8 @@
"cell_type": "code",
"metadata": {
"ExecuteTime": {
"end_time": "2025-02-05T10:14:55.608814Z",
"start_time": "2025-02-05T10:14:55.606280Z"
"end_time": "2025-02-05T11:26:14.657801Z",
"start_time": "2025-02-05T11:26:14.655785Z"
}
},
"source": [
@@ -649,7 +649,7 @@
" return Counter(y_train[k_neighbors]).most_common()[0][0]"
],
"outputs": [],
"execution_count": 137
"execution_count": 174
},
{
"cell_type": "markdown",
@@ -669,8 +669,8 @@
"cell_type": "code",
"metadata": {
"ExecuteTime": {
"end_time": "2025-02-05T10:15:10.789890Z",
"start_time": "2025-02-05T10:15:10.784635Z"
"end_time": "2025-02-05T11:26:15.309422Z",
"start_time": "2025-02-05T11:26:15.304219Z"
}
},
"source": [
@@ -690,7 +690,7 @@
]
}
],
"execution_count": 139
"execution_count": 175
},
{
"cell_type": "markdown",
@@ -710,8 +710,8 @@
"cell_type": "code",
"metadata": {
"ExecuteTime": {
"end_time": "2025-02-05T10:15:23.022403Z",
"start_time": "2025-02-05T10:15:23.019846Z"
"end_time": "2025-02-05T11:26:15.657315Z",
"start_time": "2025-02-05T11:26:15.655386Z"
}
},
"source": [
@@ -720,7 +720,7 @@
"knn_classifier_2 = KNeighborsClassifier(n_neighbors=3)"
],
"outputs": [],
"execution_count": 140
"execution_count": 176
},
{
"cell_type": "markdown",
@@ -733,8 +733,8 @@
"cell_type": "code",
"metadata": {
"ExecuteTime": {
"end_time": "2025-02-05T10:15:24.257964Z",
"start_time": "2025-02-05T10:15:24.249133Z"
"end_time": "2025-02-05T11:26:16.224590Z",
"start_time": "2025-02-05T11:26:16.219083Z"
}
},
"source": "knn_classifier_2.fit(X_train, y_train)",
@@ -745,7 +745,7 @@
"KNeighborsClassifier(n_neighbors=3)"
],
"text/html": [
"<style>#sk-container-id-3 {\n",
"<style>#sk-container-id-4 {\n",
" /* Definition of color scheme common for light and dark mode */\n",
" --sklearn-color-text: #000;\n",
" --sklearn-color-text-muted: #666;\n",
@@ -776,15 +776,15 @@
" }\n",
"}\n",
"\n",
"#sk-container-id-3 {\n",
"#sk-container-id-4 {\n",
" color: var(--sklearn-color-text);\n",
"}\n",
"\n",
"#sk-container-id-3 pre {\n",
"#sk-container-id-4 pre {\n",
" padding: 0;\n",
"}\n",
"\n",
"#sk-container-id-3 input.sk-hidden--visually {\n",
"#sk-container-id-4 input.sk-hidden--visually {\n",
" border: 0;\n",
" clip: rect(1px 1px 1px 1px);\n",
" clip: rect(1px, 1px, 1px, 1px);\n",
@@ -796,7 +796,7 @@
" width: 1px;\n",
"}\n",
"\n",
"#sk-container-id-3 div.sk-dashed-wrapped {\n",
"#sk-container-id-4 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",
@@ -804,7 +804,7 @@
" background-color: var(--sklearn-color-background);\n",
"}\n",
"\n",
"#sk-container-id-3 div.sk-container {\n",
"#sk-container-id-4 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",
@@ -814,7 +814,7 @@
" position: relative;\n",
"}\n",
"\n",
"#sk-container-id-3 div.sk-text-repr-fallback {\n",
"#sk-container-id-4 div.sk-text-repr-fallback {\n",
" display: none;\n",
"}\n",
"\n",
@@ -830,14 +830,14 @@
"\n",
"/* Parallel-specific style estimator block */\n",
"\n",
"#sk-container-id-3 div.sk-parallel-item::after {\n",
"#sk-container-id-4 div.sk-parallel-item::after {\n",
" content: \"\";\n",
" width: 100%;\n",
" border-bottom: 2px solid var(--sklearn-color-text-on-default-background);\n",
" flex-grow: 1;\n",
"}\n",
"\n",
"#sk-container-id-3 div.sk-parallel {\n",
"#sk-container-id-4 div.sk-parallel {\n",
" display: flex;\n",
" align-items: stretch;\n",
" justify-content: center;\n",
@@ -845,28 +845,28 @@
" position: relative;\n",
"}\n",
"\n",
"#sk-container-id-3 div.sk-parallel-item {\n",
"#sk-container-id-4 div.sk-parallel-item {\n",
" display: flex;\n",
" flex-direction: column;\n",
"}\n",
"\n",
"#sk-container-id-3 div.sk-parallel-item:first-child::after {\n",
"#sk-container-id-4 div.sk-parallel-item:first-child::after {\n",
" align-self: flex-end;\n",
" width: 50%;\n",
"}\n",
"\n",
"#sk-container-id-3 div.sk-parallel-item:last-child::after {\n",
"#sk-container-id-4 div.sk-parallel-item:last-child::after {\n",
" align-self: flex-start;\n",
" width: 50%;\n",
"}\n",
"\n",
"#sk-container-id-3 div.sk-parallel-item:only-child::after {\n",
"#sk-container-id-4 div.sk-parallel-item:only-child::after {\n",
" width: 0;\n",
"}\n",
"\n",
"/* Serial-specific style estimator block */\n",
"\n",
"#sk-container-id-3 div.sk-serial {\n",
"#sk-container-id-4 div.sk-serial {\n",
" display: flex;\n",
" flex-direction: column;\n",
" align-items: center;\n",
@@ -884,14 +884,14 @@
"\n",
"/* Pipeline and ColumnTransformer style (default) */\n",
"\n",
"#sk-container-id-3 div.sk-toggleable {\n",
"#sk-container-id-4 div.sk-toggleable {\n",
" /* Default theme specific background. It is overwritten whether we have a\n",
" specific estimator or a Pipeline/ColumnTransformer */\n",
" background-color: var(--sklearn-color-background);\n",
"}\n",
"\n",
"/* Toggleable label */\n",
"#sk-container-id-3 label.sk-toggleable__label {\n",
"#sk-container-id-4 label.sk-toggleable__label {\n",
" cursor: pointer;\n",
" display: flex;\n",
" width: 100%;\n",
@@ -904,13 +904,13 @@
" gap: 0.5em;\n",
"}\n",
"\n",
"#sk-container-id-3 label.sk-toggleable__label .caption {\n",
"#sk-container-id-4 label.sk-toggleable__label .caption {\n",
" font-size: 0.6rem;\n",
" font-weight: lighter;\n",
" color: var(--sklearn-color-text-muted);\n",
"}\n",
"\n",
"#sk-container-id-3 label.sk-toggleable__label-arrow:before {\n",
"#sk-container-id-4 label.sk-toggleable__label-arrow:before {\n",
" /* Arrow on the left of the label */\n",
" content: \"▸\";\n",
" float: left;\n",
@@ -918,13 +918,13 @@
" color: var(--sklearn-color-icon);\n",
"}\n",
"\n",
"#sk-container-id-3 label.sk-toggleable__label-arrow:hover:before {\n",
"#sk-container-id-4 label.sk-toggleable__label-arrow:hover:before {\n",
" color: var(--sklearn-color-text);\n",
"}\n",
"\n",
"/* Toggleable content - dropdown */\n",
"\n",
"#sk-container-id-3 div.sk-toggleable__content {\n",
"#sk-container-id-4 div.sk-toggleable__content {\n",
" max-height: 0;\n",
" max-width: 0;\n",
" overflow: hidden;\n",
@@ -933,12 +933,12 @@
" background-color: var(--sklearn-color-unfitted-level-0);\n",
"}\n",
"\n",
"#sk-container-id-3 div.sk-toggleable__content.fitted {\n",
"#sk-container-id-4 div.sk-toggleable__content.fitted {\n",
" /* fitted */\n",
" background-color: var(--sklearn-color-fitted-level-0);\n",
"}\n",
"\n",
"#sk-container-id-3 div.sk-toggleable__content pre {\n",
"#sk-container-id-4 div.sk-toggleable__content pre {\n",
" margin: 0.2em;\n",
" border-radius: 0.25em;\n",
" color: var(--sklearn-color-text);\n",
@@ -946,79 +946,79 @@
" background-color: var(--sklearn-color-unfitted-level-0);\n",
"}\n",
"\n",
"#sk-container-id-3 div.sk-toggleable__content.fitted pre {\n",
"#sk-container-id-4 div.sk-toggleable__content.fitted pre {\n",
" /* unfitted */\n",
" background-color: var(--sklearn-color-fitted-level-0);\n",
"}\n",
"\n",
"#sk-container-id-3 input.sk-toggleable__control:checked~div.sk-toggleable__content {\n",
"#sk-container-id-4 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-3 input.sk-toggleable__control:checked~label.sk-toggleable__label-arrow:before {\n",
"#sk-container-id-4 input.sk-toggleable__control:checked~label.sk-toggleable__label-arrow:before {\n",
" content: \"▾\";\n",
"}\n",
"\n",
"/* Pipeline/ColumnTransformer-specific style */\n",
"\n",
"#sk-container-id-3 div.sk-label input.sk-toggleable__control:checked~label.sk-toggleable__label {\n",
"#sk-container-id-4 div.sk-label input.sk-toggleable__control:checked~label.sk-toggleable__label {\n",
" color: var(--sklearn-color-text);\n",
" background-color: var(--sklearn-color-unfitted-level-2);\n",
"}\n",
"\n",
"#sk-container-id-3 div.sk-label.fitted input.sk-toggleable__control:checked~label.sk-toggleable__label {\n",
"#sk-container-id-4 div.sk-label.fitted input.sk-toggleable__control:checked~label.sk-toggleable__label {\n",
" background-color: var(--sklearn-color-fitted-level-2);\n",
"}\n",
"\n",
"/* Estimator-specific style */\n",
"\n",
"/* Colorize estimator box */\n",
"#sk-container-id-3 div.sk-estimator input.sk-toggleable__control:checked~label.sk-toggleable__label {\n",
"#sk-container-id-4 div.sk-estimator input.sk-toggleable__control:checked~label.sk-toggleable__label {\n",
" /* unfitted */\n",
" background-color: var(--sklearn-color-unfitted-level-2);\n",
"}\n",
"\n",
"#sk-container-id-3 div.sk-estimator.fitted input.sk-toggleable__control:checked~label.sk-toggleable__label {\n",
"#sk-container-id-4 div.sk-estimator.fitted input.sk-toggleable__control:checked~label.sk-toggleable__label {\n",
" /* fitted */\n",
" background-color: var(--sklearn-color-fitted-level-2);\n",
"}\n",
"\n",
"#sk-container-id-3 div.sk-label label.sk-toggleable__label,\n",
"#sk-container-id-3 div.sk-label label {\n",
"#sk-container-id-4 div.sk-label label.sk-toggleable__label,\n",
"#sk-container-id-4 div.sk-label label {\n",
" /* The background is the default theme color */\n",
" color: var(--sklearn-color-text-on-default-background);\n",
"}\n",
"\n",
"/* On hover, darken the color of the background */\n",
"#sk-container-id-3 div.sk-label:hover label.sk-toggleable__label {\n",
"#sk-container-id-4 div.sk-label:hover label.sk-toggleable__label {\n",
" color: var(--sklearn-color-text);\n",
" background-color: var(--sklearn-color-unfitted-level-2);\n",
"}\n",
"\n",
"/* Label box, darken color on hover, fitted */\n",
"#sk-container-id-3 div.sk-label.fitted:hover label.sk-toggleable__label.fitted {\n",
"#sk-container-id-4 div.sk-label.fitted:hover label.sk-toggleable__label.fitted {\n",
" color: var(--sklearn-color-text);\n",
" background-color: var(--sklearn-color-fitted-level-2);\n",
"}\n",
"\n",
"/* Estimator label */\n",
"\n",
"#sk-container-id-3 div.sk-label label {\n",
"#sk-container-id-4 div.sk-label label {\n",
" font-family: monospace;\n",
" font-weight: bold;\n",
" display: inline-block;\n",
" line-height: 1.2em;\n",
"}\n",
"\n",
"#sk-container-id-3 div.sk-label-container {\n",
"#sk-container-id-4 div.sk-label-container {\n",
" text-align: center;\n",
"}\n",
"\n",
"/* Estimator-specific */\n",
"#sk-container-id-3 div.sk-estimator {\n",
"#sk-container-id-4 div.sk-estimator {\n",
" font-family: monospace;\n",
" border: 1px dotted var(--sklearn-color-border-box);\n",
" border-radius: 0.25em;\n",
@@ -1028,18 +1028,18 @@
" background-color: var(--sklearn-color-unfitted-level-0);\n",
"}\n",
"\n",
"#sk-container-id-3 div.sk-estimator.fitted {\n",
"#sk-container-id-4 div.sk-estimator.fitted {\n",
" /* fitted */\n",
" background-color: var(--sklearn-color-fitted-level-0);\n",
"}\n",
"\n",
"/* on hover */\n",
"#sk-container-id-3 div.sk-estimator:hover {\n",
"#sk-container-id-4 div.sk-estimator:hover {\n",
" /* unfitted */\n",
" background-color: var(--sklearn-color-unfitted-level-2);\n",
"}\n",
"\n",
"#sk-container-id-3 div.sk-estimator.fitted:hover {\n",
"#sk-container-id-4 div.sk-estimator.fitted:hover {\n",
" /* fitted */\n",
" background-color: var(--sklearn-color-fitted-level-2);\n",
"}\n",
@@ -1127,7 +1127,7 @@
"\n",
"/* \"?\"-specific style due to the `<a>` HTML tag */\n",
"\n",
"#sk-container-id-3 a.estimator_doc_link {\n",
"#sk-container-id-4 a.estimator_doc_link {\n",
" float: right;\n",
" font-size: 1rem;\n",
" line-height: 1em;\n",
@@ -1142,33 +1142,33 @@
" border: var(--sklearn-color-unfitted-level-1) 1pt solid;\n",
"}\n",
"\n",
"#sk-container-id-3 a.estimator_doc_link.fitted {\n",
"#sk-container-id-4 a.estimator_doc_link.fitted {\n",
" /* fitted */\n",
" border: var(--sklearn-color-fitted-level-1) 1pt solid;\n",
" color: var(--sklearn-color-fitted-level-1);\n",
"}\n",
"\n",
"/* On hover */\n",
"#sk-container-id-3 a.estimator_doc_link:hover {\n",
"#sk-container-id-4 a.estimator_doc_link:hover {\n",
" /* unfitted */\n",
" background-color: var(--sklearn-color-unfitted-level-3);\n",
" color: var(--sklearn-color-background);\n",
" text-decoration: none;\n",
"}\n",
"\n",
"#sk-container-id-3 a.estimator_doc_link.fitted:hover {\n",
"#sk-container-id-4 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-3\" 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-3\" type=\"checkbox\" checked><label for=\"sk-estimator-id-3\" 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-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>"
]
},
"execution_count": 141,
"execution_count": 177,
"metadata": {},
"output_type": "execute_result"
}
],
"execution_count": 141
"execution_count": 177
},
{
"cell_type": "markdown",
@@ -1181,8 +1181,8 @@
"cell_type": "code",
"metadata": {
"ExecuteTime": {
"end_time": "2025-02-05T10:15:27.832716Z",
"start_time": "2025-02-05T10:15:27.824255Z"
"end_time": "2025-02-05T11:26:17.023370Z",
"start_time": "2025-02-05T11:26:17.018037Z"
}
},
"source": "knn_classifier_2.score(X_test, y_test)",
@@ -1193,12 +1193,12 @@
"0.98"
]
},
"execution_count": 142,
"execution_count": 178,
"metadata": {},
"output_type": "execute_result"
}
],
"execution_count": 142
"execution_count": 178
},
{
"cell_type": "markdown",
@@ -1246,8 +1246,8 @@
"cell_type": "code",
"metadata": {
"ExecuteTime": {
"end_time": "2025-02-05T10:15:33.256620Z",
"start_time": "2025-02-05T10:15:33.253659Z"
"end_time": "2025-02-05T11:26:19.505745Z",
"start_time": "2025-02-05T11:26:19.502276Z"
}
},
"source": [
@@ -1257,14 +1257,14 @@
"from sklearn.neighbors import KNeighborsClassifier"
],
"outputs": [],
"execution_count": 143
"execution_count": 179
},
{
"cell_type": "code",
"metadata": {
"ExecuteTime": {
"end_time": "2025-02-05T10:15:33.929657Z",
"start_time": "2025-02-05T10:15:33.922375Z"
"end_time": "2025-02-05T11:26:19.890538Z",
"start_time": "2025-02-05T11:26:19.887279Z"
}
},
"source": [
@@ -1288,14 +1288,14 @@
]
}
],
"execution_count": 144
"execution_count": 180
},
{
"cell_type": "code",
"metadata": {
"ExecuteTime": {
"end_time": "2025-02-05T10:15:35.156143Z",
"start_time": "2025-02-05T10:15:35.074023Z"
"end_time": "2025-02-05T11:26:20.564996Z",
"start_time": "2025-02-05T11:26:20.484918Z"
}
},
"source": [
@@ -1306,10 +1306,10 @@
{
"data": {
"text/plain": [
"<matplotlib.collections.PathCollection at 0x15f18c6b0>"
"<matplotlib.collections.PathCollection at 0x10ed75a60>"
]
},
"execution_count": 145,
"execution_count": 181,
"metadata": {},
"output_type": "execute_result"
},
@@ -1324,7 +1324,7 @@
"output_type": "display_data"
}
],
"execution_count": 145
"execution_count": 181
},
{
"cell_type": "markdown",
@@ -1337,8 +1337,8 @@
"cell_type": "code",
"metadata": {
"ExecuteTime": {
"end_time": "2025-02-05T10:15:36.377613Z",
"start_time": "2025-02-05T10:15:36.370486Z"
"end_time": "2025-02-05T11:27:09.124075Z",
"start_time": "2025-02-05T11:27:09.119577Z"
}
},
"source": [
@@ -1352,7 +1352,7 @@
" KNNs.append(knn_classifier_k)"
],
"outputs": [],
"execution_count": 146
"execution_count": 188
},
{
"cell_type": "markdown",
@@ -1365,8 +1365,8 @@
"cell_type": "code",
"metadata": {
"ExecuteTime": {
"end_time": "2025-02-05T10:16:59.443426Z",
"start_time": "2025-02-05T10:16:58.235753Z"
"end_time": "2025-02-05T11:26:42.695499Z",
"start_time": "2025-02-05T11:26:41.672308Z"
}
},
"source": [
@@ -1387,6 +1387,17 @@
"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": [
@@ -1398,7 +1409,7 @@
"output_type": "display_data"
}
],
"execution_count": 150
"execution_count": 187
},
{
"cell_type": "markdown",
@@ -2216,7 +2227,8 @@
},
"source": [
"y = y_train.ravel()\n",
"y.shape"
"y.shape\n",
"\n"
],
"outputs": [
{

File diff suppressed because one or more lines are too long

View File

Before

Width:  |  Height:  |  Size: 783 KiB

After

Width:  |  Height:  |  Size: 783 KiB

File diff suppressed because it is too large Load Diff