|
a |
|
b/Models/Model_B (1).ipynb |
|
|
1 |
{ |
|
|
2 |
"nbformat": 4, |
|
|
3 |
"nbformat_minor": 0, |
|
|
4 |
"metadata": { |
|
|
5 |
"colab": { |
|
|
6 |
"provenance": [] |
|
|
7 |
}, |
|
|
8 |
"kernelspec": { |
|
|
9 |
"name": "python3", |
|
|
10 |
"display_name": "Python 3" |
|
|
11 |
}, |
|
|
12 |
"language_info": { |
|
|
13 |
"name": "python" |
|
|
14 |
} |
|
|
15 |
}, |
|
|
16 |
"cells": [ |
|
|
17 |
{ |
|
|
18 |
"cell_type": "code", |
|
|
19 |
"execution_count": null, |
|
|
20 |
"metadata": { |
|
|
21 |
"id": "a5Vf7VhQNGDs" |
|
|
22 |
}, |
|
|
23 |
"outputs": [], |
|
|
24 |
"source": [ |
|
|
25 |
"import pandas as pd\n", |
|
|
26 |
"\n", |
|
|
27 |
"df = pd.read_csv('/content/CS279 Data - Sheet1.csv')" |
|
|
28 |
] |
|
|
29 |
}, |
|
|
30 |
{ |
|
|
31 |
"cell_type": "code", |
|
|
32 |
"source": [ |
|
|
33 |
"df = df.dropna()" |
|
|
34 |
], |
|
|
35 |
"metadata": { |
|
|
36 |
"id": "TkOLhVxqNmNR" |
|
|
37 |
}, |
|
|
38 |
"execution_count": null, |
|
|
39 |
"outputs": [] |
|
|
40 |
}, |
|
|
41 |
{ |
|
|
42 |
"cell_type": "code", |
|
|
43 |
"source": [ |
|
|
44 |
"from sklearn.preprocessing import LabelEncoder\n", |
|
|
45 |
"label_encoder = LabelEncoder()\n", |
|
|
46 |
"df['Shape_Encoded'] = label_encoder.fit_transform(df['Shape'])\n", |
|
|
47 |
"df['Color_Encoded'] = label_encoder.fit_transform(df['Color'])\n", |
|
|
48 |
"df['Diagnosis'] = label_encoder.fit_transform(df['Infected'])" |
|
|
49 |
], |
|
|
50 |
"metadata": { |
|
|
51 |
"id": "3iLH8iynNppc" |
|
|
52 |
}, |
|
|
53 |
"execution_count": null, |
|
|
54 |
"outputs": [] |
|
|
55 |
}, |
|
|
56 |
{ |
|
|
57 |
"cell_type": "code", |
|
|
58 |
"source": [ |
|
|
59 |
"X = df[['Area']]\n", |
|
|
60 |
"y = df[['Diagnosis']]" |
|
|
61 |
], |
|
|
62 |
"metadata": { |
|
|
63 |
"id": "9MrbV8gdOgAR" |
|
|
64 |
}, |
|
|
65 |
"execution_count": null, |
|
|
66 |
"outputs": [] |
|
|
67 |
}, |
|
|
68 |
{ |
|
|
69 |
"cell_type": "code", |
|
|
70 |
"source": [ |
|
|
71 |
"from sklearn.model_selection import train_test_split\n", |
|
|
72 |
"X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=42)" |
|
|
73 |
], |
|
|
74 |
"metadata": { |
|
|
75 |
"id": "yKmSraTfO300" |
|
|
76 |
}, |
|
|
77 |
"execution_count": null, |
|
|
78 |
"outputs": [] |
|
|
79 |
}, |
|
|
80 |
{ |
|
|
81 |
"cell_type": "code", |
|
|
82 |
"source": [ |
|
|
83 |
"from sklearn.linear_model import LogisticRegression\n", |
|
|
84 |
"log_reg_model = LogisticRegression(random_state=42)\n", |
|
|
85 |
"log_reg_model.fit(X_train, y_train)" |
|
|
86 |
], |
|
|
87 |
"metadata": { |
|
|
88 |
"colab": { |
|
|
89 |
"base_uri": "https://localhost:8080/", |
|
|
90 |
"height": 136 |
|
|
91 |
}, |
|
|
92 |
"id": "pRAanHQZO--R", |
|
|
93 |
"outputId": "b7e6c4ae-8364-4cb7-f2c7-0495bc22058c" |
|
|
94 |
}, |
|
|
95 |
"execution_count": null, |
|
|
96 |
"outputs": [ |
|
|
97 |
{ |
|
|
98 |
"output_type": "stream", |
|
|
99 |
"name": "stderr", |
|
|
100 |
"text": [ |
|
|
101 |
"/usr/local/lib/python3.10/dist-packages/sklearn/utils/validation.py:1339: DataConversionWarning: A column-vector y was passed when a 1d array was expected. Please change the shape of y to (n_samples, ), for example using ravel().\n", |
|
|
102 |
" y = column_or_1d(y, warn=True)\n" |
|
|
103 |
] |
|
|
104 |
}, |
|
|
105 |
{ |
|
|
106 |
"output_type": "execute_result", |
|
|
107 |
"data": { |
|
|
108 |
"text/plain": [ |
|
|
109 |
"LogisticRegression(random_state=42)" |
|
|
110 |
], |
|
|
111 |
"text/html": [ |
|
|
112 |
"<style>#sk-container-id-2 {\n", |
|
|
113 |
" /* Definition of color scheme common for light and dark mode */\n", |
|
|
114 |
" --sklearn-color-text: black;\n", |
|
|
115 |
" --sklearn-color-line: gray;\n", |
|
|
116 |
" /* Definition of color scheme for unfitted estimators */\n", |
|
|
117 |
" --sklearn-color-unfitted-level-0: #fff5e6;\n", |
|
|
118 |
" --sklearn-color-unfitted-level-1: #f6e4d2;\n", |
|
|
119 |
" --sklearn-color-unfitted-level-2: #ffe0b3;\n", |
|
|
120 |
" --sklearn-color-unfitted-level-3: chocolate;\n", |
|
|
121 |
" /* Definition of color scheme for fitted estimators */\n", |
|
|
122 |
" --sklearn-color-fitted-level-0: #f0f8ff;\n", |
|
|
123 |
" --sklearn-color-fitted-level-1: #d4ebff;\n", |
|
|
124 |
" --sklearn-color-fitted-level-2: #b3dbfd;\n", |
|
|
125 |
" --sklearn-color-fitted-level-3: cornflowerblue;\n", |
|
|
126 |
"\n", |
|
|
127 |
" /* Specific color for light theme */\n", |
|
|
128 |
" --sklearn-color-text-on-default-background: var(--sg-text-color, var(--theme-code-foreground, var(--jp-content-font-color1, black)));\n", |
|
|
129 |
" --sklearn-color-background: var(--sg-background-color, var(--theme-background, var(--jp-layout-color0, white)));\n", |
|
|
130 |
" --sklearn-color-border-box: var(--sg-text-color, var(--theme-code-foreground, var(--jp-content-font-color1, black)));\n", |
|
|
131 |
" --sklearn-color-icon: #696969;\n", |
|
|
132 |
"\n", |
|
|
133 |
" @media (prefers-color-scheme: dark) {\n", |
|
|
134 |
" /* Redefinition of color scheme for dark theme */\n", |
|
|
135 |
" --sklearn-color-text-on-default-background: var(--sg-text-color, var(--theme-code-foreground, var(--jp-content-font-color1, white)));\n", |
|
|
136 |
" --sklearn-color-background: var(--sg-background-color, var(--theme-background, var(--jp-layout-color0, #111)));\n", |
|
|
137 |
" --sklearn-color-border-box: var(--sg-text-color, var(--theme-code-foreground, var(--jp-content-font-color1, white)));\n", |
|
|
138 |
" --sklearn-color-icon: #878787;\n", |
|
|
139 |
" }\n", |
|
|
140 |
"}\n", |
|
|
141 |
"\n", |
|
|
142 |
"#sk-container-id-2 {\n", |
|
|
143 |
" color: var(--sklearn-color-text);\n", |
|
|
144 |
"}\n", |
|
|
145 |
"\n", |
|
|
146 |
"#sk-container-id-2 pre {\n", |
|
|
147 |
" padding: 0;\n", |
|
|
148 |
"}\n", |
|
|
149 |
"\n", |
|
|
150 |
"#sk-container-id-2 input.sk-hidden--visually {\n", |
|
|
151 |
" border: 0;\n", |
|
|
152 |
" clip: rect(1px 1px 1px 1px);\n", |
|
|
153 |
" clip: rect(1px, 1px, 1px, 1px);\n", |
|
|
154 |
" height: 1px;\n", |
|
|
155 |
" margin: -1px;\n", |
|
|
156 |
" overflow: hidden;\n", |
|
|
157 |
" padding: 0;\n", |
|
|
158 |
" position: absolute;\n", |
|
|
159 |
" width: 1px;\n", |
|
|
160 |
"}\n", |
|
|
161 |
"\n", |
|
|
162 |
"#sk-container-id-2 div.sk-dashed-wrapped {\n", |
|
|
163 |
" border: 1px dashed var(--sklearn-color-line);\n", |
|
|
164 |
" margin: 0 0.4em 0.5em 0.4em;\n", |
|
|
165 |
" box-sizing: border-box;\n", |
|
|
166 |
" padding-bottom: 0.4em;\n", |
|
|
167 |
" background-color: var(--sklearn-color-background);\n", |
|
|
168 |
"}\n", |
|
|
169 |
"\n", |
|
|
170 |
"#sk-container-id-2 div.sk-container {\n", |
|
|
171 |
" /* jupyter's `normalize.less` sets `[hidden] { display: none; }`\n", |
|
|
172 |
" but bootstrap.min.css set `[hidden] { display: none !important; }`\n", |
|
|
173 |
" so we also need the `!important` here to be able to override the\n", |
|
|
174 |
" default hidden behavior on the sphinx rendered scikit-learn.org.\n", |
|
|
175 |
" See: https://github.com/scikit-learn/scikit-learn/issues/21755 */\n", |
|
|
176 |
" display: inline-block !important;\n", |
|
|
177 |
" position: relative;\n", |
|
|
178 |
"}\n", |
|
|
179 |
"\n", |
|
|
180 |
"#sk-container-id-2 div.sk-text-repr-fallback {\n", |
|
|
181 |
" display: none;\n", |
|
|
182 |
"}\n", |
|
|
183 |
"\n", |
|
|
184 |
"div.sk-parallel-item,\n", |
|
|
185 |
"div.sk-serial,\n", |
|
|
186 |
"div.sk-item {\n", |
|
|
187 |
" /* draw centered vertical line to link estimators */\n", |
|
|
188 |
" background-image: linear-gradient(var(--sklearn-color-text-on-default-background), var(--sklearn-color-text-on-default-background));\n", |
|
|
189 |
" background-size: 2px 100%;\n", |
|
|
190 |
" background-repeat: no-repeat;\n", |
|
|
191 |
" background-position: center center;\n", |
|
|
192 |
"}\n", |
|
|
193 |
"\n", |
|
|
194 |
"/* Parallel-specific style estimator block */\n", |
|
|
195 |
"\n", |
|
|
196 |
"#sk-container-id-2 div.sk-parallel-item::after {\n", |
|
|
197 |
" content: \"\";\n", |
|
|
198 |
" width: 100%;\n", |
|
|
199 |
" border-bottom: 2px solid var(--sklearn-color-text-on-default-background);\n", |
|
|
200 |
" flex-grow: 1;\n", |
|
|
201 |
"}\n", |
|
|
202 |
"\n", |
|
|
203 |
"#sk-container-id-2 div.sk-parallel {\n", |
|
|
204 |
" display: flex;\n", |
|
|
205 |
" align-items: stretch;\n", |
|
|
206 |
" justify-content: center;\n", |
|
|
207 |
" background-color: var(--sklearn-color-background);\n", |
|
|
208 |
" position: relative;\n", |
|
|
209 |
"}\n", |
|
|
210 |
"\n", |
|
|
211 |
"#sk-container-id-2 div.sk-parallel-item {\n", |
|
|
212 |
" display: flex;\n", |
|
|
213 |
" flex-direction: column;\n", |
|
|
214 |
"}\n", |
|
|
215 |
"\n", |
|
|
216 |
"#sk-container-id-2 div.sk-parallel-item:first-child::after {\n", |
|
|
217 |
" align-self: flex-end;\n", |
|
|
218 |
" width: 50%;\n", |
|
|
219 |
"}\n", |
|
|
220 |
"\n", |
|
|
221 |
"#sk-container-id-2 div.sk-parallel-item:last-child::after {\n", |
|
|
222 |
" align-self: flex-start;\n", |
|
|
223 |
" width: 50%;\n", |
|
|
224 |
"}\n", |
|
|
225 |
"\n", |
|
|
226 |
"#sk-container-id-2 div.sk-parallel-item:only-child::after {\n", |
|
|
227 |
" width: 0;\n", |
|
|
228 |
"}\n", |
|
|
229 |
"\n", |
|
|
230 |
"/* Serial-specific style estimator block */\n", |
|
|
231 |
"\n", |
|
|
232 |
"#sk-container-id-2 div.sk-serial {\n", |
|
|
233 |
" display: flex;\n", |
|
|
234 |
" flex-direction: column;\n", |
|
|
235 |
" align-items: center;\n", |
|
|
236 |
" background-color: var(--sklearn-color-background);\n", |
|
|
237 |
" padding-right: 1em;\n", |
|
|
238 |
" padding-left: 1em;\n", |
|
|
239 |
"}\n", |
|
|
240 |
"\n", |
|
|
241 |
"\n", |
|
|
242 |
"/* Toggleable style: style used for estimator/Pipeline/ColumnTransformer box that is\n", |
|
|
243 |
"clickable and can be expanded/collapsed.\n", |
|
|
244 |
"- Pipeline and ColumnTransformer use this feature and define the default style\n", |
|
|
245 |
"- Estimators will overwrite some part of the style using the `sk-estimator` class\n", |
|
|
246 |
"*/\n", |
|
|
247 |
"\n", |
|
|
248 |
"/* Pipeline and ColumnTransformer style (default) */\n", |
|
|
249 |
"\n", |
|
|
250 |
"#sk-container-id-2 div.sk-toggleable {\n", |
|
|
251 |
" /* Default theme specific background. It is overwritten whether we have a\n", |
|
|
252 |
" specific estimator or a Pipeline/ColumnTransformer */\n", |
|
|
253 |
" background-color: var(--sklearn-color-background);\n", |
|
|
254 |
"}\n", |
|
|
255 |
"\n", |
|
|
256 |
"/* Toggleable label */\n", |
|
|
257 |
"#sk-container-id-2 label.sk-toggleable__label {\n", |
|
|
258 |
" cursor: pointer;\n", |
|
|
259 |
" display: block;\n", |
|
|
260 |
" width: 100%;\n", |
|
|
261 |
" margin-bottom: 0;\n", |
|
|
262 |
" padding: 0.5em;\n", |
|
|
263 |
" box-sizing: border-box;\n", |
|
|
264 |
" text-align: center;\n", |
|
|
265 |
"}\n", |
|
|
266 |
"\n", |
|
|
267 |
"#sk-container-id-2 label.sk-toggleable__label-arrow:before {\n", |
|
|
268 |
" /* Arrow on the left of the label */\n", |
|
|
269 |
" content: \"▸\";\n", |
|
|
270 |
" float: left;\n", |
|
|
271 |
" margin-right: 0.25em;\n", |
|
|
272 |
" color: var(--sklearn-color-icon);\n", |
|
|
273 |
"}\n", |
|
|
274 |
"\n", |
|
|
275 |
"#sk-container-id-2 label.sk-toggleable__label-arrow:hover:before {\n", |
|
|
276 |
" color: var(--sklearn-color-text);\n", |
|
|
277 |
"}\n", |
|
|
278 |
"\n", |
|
|
279 |
"/* Toggleable content - dropdown */\n", |
|
|
280 |
"\n", |
|
|
281 |
"#sk-container-id-2 div.sk-toggleable__content {\n", |
|
|
282 |
" max-height: 0;\n", |
|
|
283 |
" max-width: 0;\n", |
|
|
284 |
" overflow: hidden;\n", |
|
|
285 |
" text-align: left;\n", |
|
|
286 |
" /* unfitted */\n", |
|
|
287 |
" background-color: var(--sklearn-color-unfitted-level-0);\n", |
|
|
288 |
"}\n", |
|
|
289 |
"\n", |
|
|
290 |
"#sk-container-id-2 div.sk-toggleable__content.fitted {\n", |
|
|
291 |
" /* fitted */\n", |
|
|
292 |
" background-color: var(--sklearn-color-fitted-level-0);\n", |
|
|
293 |
"}\n", |
|
|
294 |
"\n", |
|
|
295 |
"#sk-container-id-2 div.sk-toggleable__content pre {\n", |
|
|
296 |
" margin: 0.2em;\n", |
|
|
297 |
" border-radius: 0.25em;\n", |
|
|
298 |
" color: var(--sklearn-color-text);\n", |
|
|
299 |
" /* unfitted */\n", |
|
|
300 |
" background-color: var(--sklearn-color-unfitted-level-0);\n", |
|
|
301 |
"}\n", |
|
|
302 |
"\n", |
|
|
303 |
"#sk-container-id-2 div.sk-toggleable__content.fitted pre {\n", |
|
|
304 |
" /* unfitted */\n", |
|
|
305 |
" background-color: var(--sklearn-color-fitted-level-0);\n", |
|
|
306 |
"}\n", |
|
|
307 |
"\n", |
|
|
308 |
"#sk-container-id-2 input.sk-toggleable__control:checked~div.sk-toggleable__content {\n", |
|
|
309 |
" /* Expand drop-down */\n", |
|
|
310 |
" max-height: 200px;\n", |
|
|
311 |
" max-width: 100%;\n", |
|
|
312 |
" overflow: auto;\n", |
|
|
313 |
"}\n", |
|
|
314 |
"\n", |
|
|
315 |
"#sk-container-id-2 input.sk-toggleable__control:checked~label.sk-toggleable__label-arrow:before {\n", |
|
|
316 |
" content: \"▾\";\n", |
|
|
317 |
"}\n", |
|
|
318 |
"\n", |
|
|
319 |
"/* Pipeline/ColumnTransformer-specific style */\n", |
|
|
320 |
"\n", |
|
|
321 |
"#sk-container-id-2 div.sk-label input.sk-toggleable__control:checked~label.sk-toggleable__label {\n", |
|
|
322 |
" color: var(--sklearn-color-text);\n", |
|
|
323 |
" background-color: var(--sklearn-color-unfitted-level-2);\n", |
|
|
324 |
"}\n", |
|
|
325 |
"\n", |
|
|
326 |
"#sk-container-id-2 div.sk-label.fitted input.sk-toggleable__control:checked~label.sk-toggleable__label {\n", |
|
|
327 |
" background-color: var(--sklearn-color-fitted-level-2);\n", |
|
|
328 |
"}\n", |
|
|
329 |
"\n", |
|
|
330 |
"/* Estimator-specific style */\n", |
|
|
331 |
"\n", |
|
|
332 |
"/* Colorize estimator box */\n", |
|
|
333 |
"#sk-container-id-2 div.sk-estimator input.sk-toggleable__control:checked~label.sk-toggleable__label {\n", |
|
|
334 |
" /* unfitted */\n", |
|
|
335 |
" background-color: var(--sklearn-color-unfitted-level-2);\n", |
|
|
336 |
"}\n", |
|
|
337 |
"\n", |
|
|
338 |
"#sk-container-id-2 div.sk-estimator.fitted input.sk-toggleable__control:checked~label.sk-toggleable__label {\n", |
|
|
339 |
" /* fitted */\n", |
|
|
340 |
" background-color: var(--sklearn-color-fitted-level-2);\n", |
|
|
341 |
"}\n", |
|
|
342 |
"\n", |
|
|
343 |
"#sk-container-id-2 div.sk-label label.sk-toggleable__label,\n", |
|
|
344 |
"#sk-container-id-2 div.sk-label label {\n", |
|
|
345 |
" /* The background is the default theme color */\n", |
|
|
346 |
" color: var(--sklearn-color-text-on-default-background);\n", |
|
|
347 |
"}\n", |
|
|
348 |
"\n", |
|
|
349 |
"/* On hover, darken the color of the background */\n", |
|
|
350 |
"#sk-container-id-2 div.sk-label:hover label.sk-toggleable__label {\n", |
|
|
351 |
" color: var(--sklearn-color-text);\n", |
|
|
352 |
" background-color: var(--sklearn-color-unfitted-level-2);\n", |
|
|
353 |
"}\n", |
|
|
354 |
"\n", |
|
|
355 |
"/* Label box, darken color on hover, fitted */\n", |
|
|
356 |
"#sk-container-id-2 div.sk-label.fitted:hover label.sk-toggleable__label.fitted {\n", |
|
|
357 |
" color: var(--sklearn-color-text);\n", |
|
|
358 |
" background-color: var(--sklearn-color-fitted-level-2);\n", |
|
|
359 |
"}\n", |
|
|
360 |
"\n", |
|
|
361 |
"/* Estimator label */\n", |
|
|
362 |
"\n", |
|
|
363 |
"#sk-container-id-2 div.sk-label label {\n", |
|
|
364 |
" font-family: monospace;\n", |
|
|
365 |
" font-weight: bold;\n", |
|
|
366 |
" display: inline-block;\n", |
|
|
367 |
" line-height: 1.2em;\n", |
|
|
368 |
"}\n", |
|
|
369 |
"\n", |
|
|
370 |
"#sk-container-id-2 div.sk-label-container {\n", |
|
|
371 |
" text-align: center;\n", |
|
|
372 |
"}\n", |
|
|
373 |
"\n", |
|
|
374 |
"/* Estimator-specific */\n", |
|
|
375 |
"#sk-container-id-2 div.sk-estimator {\n", |
|
|
376 |
" font-family: monospace;\n", |
|
|
377 |
" border: 1px dotted var(--sklearn-color-border-box);\n", |
|
|
378 |
" border-radius: 0.25em;\n", |
|
|
379 |
" box-sizing: border-box;\n", |
|
|
380 |
" margin-bottom: 0.5em;\n", |
|
|
381 |
" /* unfitted */\n", |
|
|
382 |
" background-color: var(--sklearn-color-unfitted-level-0);\n", |
|
|
383 |
"}\n", |
|
|
384 |
"\n", |
|
|
385 |
"#sk-container-id-2 div.sk-estimator.fitted {\n", |
|
|
386 |
" /* fitted */\n", |
|
|
387 |
" background-color: var(--sklearn-color-fitted-level-0);\n", |
|
|
388 |
"}\n", |
|
|
389 |
"\n", |
|
|
390 |
"/* on hover */\n", |
|
|
391 |
"#sk-container-id-2 div.sk-estimator:hover {\n", |
|
|
392 |
" /* unfitted */\n", |
|
|
393 |
" background-color: var(--sklearn-color-unfitted-level-2);\n", |
|
|
394 |
"}\n", |
|
|
395 |
"\n", |
|
|
396 |
"#sk-container-id-2 div.sk-estimator.fitted:hover {\n", |
|
|
397 |
" /* fitted */\n", |
|
|
398 |
" background-color: var(--sklearn-color-fitted-level-2);\n", |
|
|
399 |
"}\n", |
|
|
400 |
"\n", |
|
|
401 |
"/* Specification for estimator info (e.g. \"i\" and \"?\") */\n", |
|
|
402 |
"\n", |
|
|
403 |
"/* Common style for \"i\" and \"?\" */\n", |
|
|
404 |
"\n", |
|
|
405 |
".sk-estimator-doc-link,\n", |
|
|
406 |
"a:link.sk-estimator-doc-link,\n", |
|
|
407 |
"a:visited.sk-estimator-doc-link {\n", |
|
|
408 |
" float: right;\n", |
|
|
409 |
" font-size: smaller;\n", |
|
|
410 |
" line-height: 1em;\n", |
|
|
411 |
" font-family: monospace;\n", |
|
|
412 |
" background-color: var(--sklearn-color-background);\n", |
|
|
413 |
" border-radius: 1em;\n", |
|
|
414 |
" height: 1em;\n", |
|
|
415 |
" width: 1em;\n", |
|
|
416 |
" text-decoration: none !important;\n", |
|
|
417 |
" margin-left: 1ex;\n", |
|
|
418 |
" /* unfitted */\n", |
|
|
419 |
" border: var(--sklearn-color-unfitted-level-1) 1pt solid;\n", |
|
|
420 |
" color: var(--sklearn-color-unfitted-level-1);\n", |
|
|
421 |
"}\n", |
|
|
422 |
"\n", |
|
|
423 |
".sk-estimator-doc-link.fitted,\n", |
|
|
424 |
"a:link.sk-estimator-doc-link.fitted,\n", |
|
|
425 |
"a:visited.sk-estimator-doc-link.fitted {\n", |
|
|
426 |
" /* fitted */\n", |
|
|
427 |
" border: var(--sklearn-color-fitted-level-1) 1pt solid;\n", |
|
|
428 |
" color: var(--sklearn-color-fitted-level-1);\n", |
|
|
429 |
"}\n", |
|
|
430 |
"\n", |
|
|
431 |
"/* On hover */\n", |
|
|
432 |
"div.sk-estimator:hover .sk-estimator-doc-link:hover,\n", |
|
|
433 |
".sk-estimator-doc-link:hover,\n", |
|
|
434 |
"div.sk-label-container:hover .sk-estimator-doc-link:hover,\n", |
|
|
435 |
".sk-estimator-doc-link:hover {\n", |
|
|
436 |
" /* unfitted */\n", |
|
|
437 |
" background-color: var(--sklearn-color-unfitted-level-3);\n", |
|
|
438 |
" color: var(--sklearn-color-background);\n", |
|
|
439 |
" text-decoration: none;\n", |
|
|
440 |
"}\n", |
|
|
441 |
"\n", |
|
|
442 |
"div.sk-estimator.fitted:hover .sk-estimator-doc-link.fitted:hover,\n", |
|
|
443 |
".sk-estimator-doc-link.fitted:hover,\n", |
|
|
444 |
"div.sk-label-container:hover .sk-estimator-doc-link.fitted:hover,\n", |
|
|
445 |
".sk-estimator-doc-link.fitted:hover {\n", |
|
|
446 |
" /* fitted */\n", |
|
|
447 |
" background-color: var(--sklearn-color-fitted-level-3);\n", |
|
|
448 |
" color: var(--sklearn-color-background);\n", |
|
|
449 |
" text-decoration: none;\n", |
|
|
450 |
"}\n", |
|
|
451 |
"\n", |
|
|
452 |
"/* Span, style for the box shown on hovering the info icon */\n", |
|
|
453 |
".sk-estimator-doc-link span {\n", |
|
|
454 |
" display: none;\n", |
|
|
455 |
" z-index: 9999;\n", |
|
|
456 |
" position: relative;\n", |
|
|
457 |
" font-weight: normal;\n", |
|
|
458 |
" right: .2ex;\n", |
|
|
459 |
" padding: .5ex;\n", |
|
|
460 |
" margin: .5ex;\n", |
|
|
461 |
" width: min-content;\n", |
|
|
462 |
" min-width: 20ex;\n", |
|
|
463 |
" max-width: 50ex;\n", |
|
|
464 |
" color: var(--sklearn-color-text);\n", |
|
|
465 |
" box-shadow: 2pt 2pt 4pt #999;\n", |
|
|
466 |
" /* unfitted */\n", |
|
|
467 |
" background: var(--sklearn-color-unfitted-level-0);\n", |
|
|
468 |
" border: .5pt solid var(--sklearn-color-unfitted-level-3);\n", |
|
|
469 |
"}\n", |
|
|
470 |
"\n", |
|
|
471 |
".sk-estimator-doc-link.fitted span {\n", |
|
|
472 |
" /* fitted */\n", |
|
|
473 |
" background: var(--sklearn-color-fitted-level-0);\n", |
|
|
474 |
" border: var(--sklearn-color-fitted-level-3);\n", |
|
|
475 |
"}\n", |
|
|
476 |
"\n", |
|
|
477 |
".sk-estimator-doc-link:hover span {\n", |
|
|
478 |
" display: block;\n", |
|
|
479 |
"}\n", |
|
|
480 |
"\n", |
|
|
481 |
"/* \"?\"-specific style due to the `<a>` HTML tag */\n", |
|
|
482 |
"\n", |
|
|
483 |
"#sk-container-id-2 a.estimator_doc_link {\n", |
|
|
484 |
" float: right;\n", |
|
|
485 |
" font-size: 1rem;\n", |
|
|
486 |
" line-height: 1em;\n", |
|
|
487 |
" font-family: monospace;\n", |
|
|
488 |
" background-color: var(--sklearn-color-background);\n", |
|
|
489 |
" border-radius: 1rem;\n", |
|
|
490 |
" height: 1rem;\n", |
|
|
491 |
" width: 1rem;\n", |
|
|
492 |
" text-decoration: none;\n", |
|
|
493 |
" /* unfitted */\n", |
|
|
494 |
" color: var(--sklearn-color-unfitted-level-1);\n", |
|
|
495 |
" border: var(--sklearn-color-unfitted-level-1) 1pt solid;\n", |
|
|
496 |
"}\n", |
|
|
497 |
"\n", |
|
|
498 |
"#sk-container-id-2 a.estimator_doc_link.fitted {\n", |
|
|
499 |
" /* fitted */\n", |
|
|
500 |
" border: var(--sklearn-color-fitted-level-1) 1pt solid;\n", |
|
|
501 |
" color: var(--sklearn-color-fitted-level-1);\n", |
|
|
502 |
"}\n", |
|
|
503 |
"\n", |
|
|
504 |
"/* On hover */\n", |
|
|
505 |
"#sk-container-id-2 a.estimator_doc_link:hover {\n", |
|
|
506 |
" /* unfitted */\n", |
|
|
507 |
" background-color: var(--sklearn-color-unfitted-level-3);\n", |
|
|
508 |
" color: var(--sklearn-color-background);\n", |
|
|
509 |
" text-decoration: none;\n", |
|
|
510 |
"}\n", |
|
|
511 |
"\n", |
|
|
512 |
"#sk-container-id-2 a.estimator_doc_link.fitted:hover {\n", |
|
|
513 |
" /* fitted */\n", |
|
|
514 |
" background-color: var(--sklearn-color-fitted-level-3);\n", |
|
|
515 |
"}\n", |
|
|
516 |
"</style><div id=\"sk-container-id-2\" class=\"sk-top-container\"><div class=\"sk-text-repr-fallback\"><pre>LogisticRegression(random_state=42)</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-2\" type=\"checkbox\" checked><label for=\"sk-estimator-id-2\" class=\"sk-toggleable__label fitted sk-toggleable__label-arrow fitted\"> LogisticRegression<a class=\"sk-estimator-doc-link fitted\" rel=\"noreferrer\" target=\"_blank\" href=\"https://scikit-learn.org/1.5/modules/generated/sklearn.linear_model.LogisticRegression.html\">?<span>Documentation for LogisticRegression</span></a><span class=\"sk-estimator-doc-link fitted\">i<span>Fitted</span></span></label><div class=\"sk-toggleable__content fitted\"><pre>LogisticRegression(random_state=42)</pre></div> </div></div></div></div>" |
|
|
517 |
] |
|
|
518 |
}, |
|
|
519 |
"metadata": {}, |
|
|
520 |
"execution_count": 17 |
|
|
521 |
} |
|
|
522 |
] |
|
|
523 |
}, |
|
|
524 |
{ |
|
|
525 |
"cell_type": "code", |
|
|
526 |
"source": [ |
|
|
527 |
"from sklearn.metrics import accuracy_score, precision_score, recall_score, f1_score, confusion_matrix\n", |
|
|
528 |
"from sklearn.metrics import roc_auc_score" |
|
|
529 |
], |
|
|
530 |
"metadata": { |
|
|
531 |
"id": "0J50xt-YPlio" |
|
|
532 |
}, |
|
|
533 |
"execution_count": null, |
|
|
534 |
"outputs": [] |
|
|
535 |
}, |
|
|
536 |
{ |
|
|
537 |
"cell_type": "code", |
|
|
538 |
"source": [ |
|
|
539 |
"y_pred = log_reg_model.predict(X_test)\n", |
|
|
540 |
"accuracy = accuracy_score(y_test, y_pred)\n", |
|
|
541 |
"precision = precision_score(y_test, y_pred)\n", |
|
|
542 |
"recall = recall_score(y_test, y_pred)\n", |
|
|
543 |
"f1 = f1_score(y_test, y_pred)" |
|
|
544 |
], |
|
|
545 |
"metadata": { |
|
|
546 |
"id": "WgLjC2AfPnZg" |
|
|
547 |
}, |
|
|
548 |
"execution_count": null, |
|
|
549 |
"outputs": [] |
|
|
550 |
}, |
|
|
551 |
{ |
|
|
552 |
"cell_type": "code", |
|
|
553 |
"source": [ |
|
|
554 |
"y_scores = log_reg_model.predict_proba(X_test)[:, 1]\n", |
|
|
555 |
"\n", |
|
|
556 |
"# Compute the ROC AUC score\n", |
|
|
557 |
"roc_auc = roc_auc_score(y_test, y_scores)\n", |
|
|
558 |
"\n", |
|
|
559 |
"print(f\"ROC AUC Score: {roc_auc:.2f}\")" |
|
|
560 |
], |
|
|
561 |
"metadata": { |
|
|
562 |
"colab": { |
|
|
563 |
"base_uri": "https://localhost:8080/" |
|
|
564 |
}, |
|
|
565 |
"id": "JKbm1CT6PwDa", |
|
|
566 |
"outputId": "fa7ef655-f7df-438c-a022-e6427c0549d7" |
|
|
567 |
}, |
|
|
568 |
"execution_count": null, |
|
|
569 |
"outputs": [ |
|
|
570 |
{ |
|
|
571 |
"output_type": "stream", |
|
|
572 |
"name": "stdout", |
|
|
573 |
"text": [ |
|
|
574 |
"ROC AUC Score: 0.94\n" |
|
|
575 |
] |
|
|
576 |
} |
|
|
577 |
] |
|
|
578 |
}, |
|
|
579 |
{ |
|
|
580 |
"cell_type": "code", |
|
|
581 |
"source": [ |
|
|
582 |
"print(f'Accuracy: {accuracy * 100:.2f}%')\n", |
|
|
583 |
"print(f'Precision: {precision * 100:.2f}%')\n", |
|
|
584 |
"print(f'Recall: {recall * 100:.2f}%')\n", |
|
|
585 |
"print(f'F1 Score: {f1 * 100:.2f}%')" |
|
|
586 |
], |
|
|
587 |
"metadata": { |
|
|
588 |
"colab": { |
|
|
589 |
"base_uri": "https://localhost:8080/" |
|
|
590 |
}, |
|
|
591 |
"id": "bkUrSfC0Pzul", |
|
|
592 |
"outputId": "29a0e64c-40f3-417e-8300-b841403ccaea" |
|
|
593 |
}, |
|
|
594 |
"execution_count": null, |
|
|
595 |
"outputs": [ |
|
|
596 |
{ |
|
|
597 |
"output_type": "stream", |
|
|
598 |
"name": "stdout", |
|
|
599 |
"text": [ |
|
|
600 |
"Accuracy: 91.67%\n", |
|
|
601 |
"Precision: 66.67%\n", |
|
|
602 |
"Recall: 80.00%\n", |
|
|
603 |
"F1 Score: 72.73%\n" |
|
|
604 |
] |
|
|
605 |
} |
|
|
606 |
] |
|
|
607 |
} |
|
|
608 |
] |
|
|
609 |
} |