|
a |
|
b/heart_disease.ipynb |
|
|
1 |
{ |
|
|
2 |
"cells": [ |
|
|
3 |
{ |
|
|
4 |
"cell_type": "markdown", |
|
|
5 |
"id": "41bc3d29-1e2f-41ec-b919-37d014f4769b", |
|
|
6 |
"metadata": {}, |
|
|
7 |
"source": [ |
|
|
8 |
"HEART DISEASE\n" |
|
|
9 |
] |
|
|
10 |
}, |
|
|
11 |
{ |
|
|
12 |
"cell_type": "code", |
|
|
13 |
"execution_count": 1, |
|
|
14 |
"id": "596f49af-da22-40fd-b931-972608d711f9", |
|
|
15 |
"metadata": {}, |
|
|
16 |
"outputs": [ |
|
|
17 |
{ |
|
|
18 |
"data": { |
|
|
19 |
"text/html": [ |
|
|
20 |
"<div>\n", |
|
|
21 |
"<style scoped>\n", |
|
|
22 |
" .dataframe tbody tr th:only-of-type {\n", |
|
|
23 |
" vertical-align: middle;\n", |
|
|
24 |
" }\n", |
|
|
25 |
"\n", |
|
|
26 |
" .dataframe tbody tr th {\n", |
|
|
27 |
" vertical-align: top;\n", |
|
|
28 |
" }\n", |
|
|
29 |
"\n", |
|
|
30 |
" .dataframe thead th {\n", |
|
|
31 |
" text-align: right;\n", |
|
|
32 |
" }\n", |
|
|
33 |
"</style>\n", |
|
|
34 |
"<table border=\"1\" class=\"dataframe\">\n", |
|
|
35 |
" <thead>\n", |
|
|
36 |
" <tr style=\"text-align: right;\">\n", |
|
|
37 |
" <th></th>\n", |
|
|
38 |
" <th>age</th>\n", |
|
|
39 |
" <th>sex</th>\n", |
|
|
40 |
" <th>cp</th>\n", |
|
|
41 |
" <th>trestbps</th>\n", |
|
|
42 |
" <th>chol</th>\n", |
|
|
43 |
" <th>fbs</th>\n", |
|
|
44 |
" <th>restecg</th>\n", |
|
|
45 |
" <th>thalach</th>\n", |
|
|
46 |
" <th>exang</th>\n", |
|
|
47 |
" <th>oldpeak</th>\n", |
|
|
48 |
" <th>slope</th>\n", |
|
|
49 |
" <th>ca</th>\n", |
|
|
50 |
" <th>thal</th>\n", |
|
|
51 |
" <th>target</th>\n", |
|
|
52 |
" </tr>\n", |
|
|
53 |
" </thead>\n", |
|
|
54 |
" <tbody>\n", |
|
|
55 |
" <tr>\n", |
|
|
56 |
" <th>0</th>\n", |
|
|
57 |
" <td>63</td>\n", |
|
|
58 |
" <td>1</td>\n", |
|
|
59 |
" <td>3</td>\n", |
|
|
60 |
" <td>145</td>\n", |
|
|
61 |
" <td>233</td>\n", |
|
|
62 |
" <td>1</td>\n", |
|
|
63 |
" <td>0</td>\n", |
|
|
64 |
" <td>150</td>\n", |
|
|
65 |
" <td>0</td>\n", |
|
|
66 |
" <td>2.3</td>\n", |
|
|
67 |
" <td>0</td>\n", |
|
|
68 |
" <td>0</td>\n", |
|
|
69 |
" <td>1</td>\n", |
|
|
70 |
" <td>1</td>\n", |
|
|
71 |
" </tr>\n", |
|
|
72 |
" <tr>\n", |
|
|
73 |
" <th>1</th>\n", |
|
|
74 |
" <td>37</td>\n", |
|
|
75 |
" <td>1</td>\n", |
|
|
76 |
" <td>2</td>\n", |
|
|
77 |
" <td>130</td>\n", |
|
|
78 |
" <td>250</td>\n", |
|
|
79 |
" <td>0</td>\n", |
|
|
80 |
" <td>1</td>\n", |
|
|
81 |
" <td>187</td>\n", |
|
|
82 |
" <td>0</td>\n", |
|
|
83 |
" <td>3.5</td>\n", |
|
|
84 |
" <td>0</td>\n", |
|
|
85 |
" <td>0</td>\n", |
|
|
86 |
" <td>2</td>\n", |
|
|
87 |
" <td>1</td>\n", |
|
|
88 |
" </tr>\n", |
|
|
89 |
" <tr>\n", |
|
|
90 |
" <th>2</th>\n", |
|
|
91 |
" <td>41</td>\n", |
|
|
92 |
" <td>0</td>\n", |
|
|
93 |
" <td>1</td>\n", |
|
|
94 |
" <td>130</td>\n", |
|
|
95 |
" <td>204</td>\n", |
|
|
96 |
" <td>0</td>\n", |
|
|
97 |
" <td>0</td>\n", |
|
|
98 |
" <td>172</td>\n", |
|
|
99 |
" <td>0</td>\n", |
|
|
100 |
" <td>1.4</td>\n", |
|
|
101 |
" <td>2</td>\n", |
|
|
102 |
" <td>0</td>\n", |
|
|
103 |
" <td>2</td>\n", |
|
|
104 |
" <td>1</td>\n", |
|
|
105 |
" </tr>\n", |
|
|
106 |
" <tr>\n", |
|
|
107 |
" <th>3</th>\n", |
|
|
108 |
" <td>56</td>\n", |
|
|
109 |
" <td>1</td>\n", |
|
|
110 |
" <td>1</td>\n", |
|
|
111 |
" <td>120</td>\n", |
|
|
112 |
" <td>236</td>\n", |
|
|
113 |
" <td>0</td>\n", |
|
|
114 |
" <td>1</td>\n", |
|
|
115 |
" <td>178</td>\n", |
|
|
116 |
" <td>0</td>\n", |
|
|
117 |
" <td>0.8</td>\n", |
|
|
118 |
" <td>2</td>\n", |
|
|
119 |
" <td>0</td>\n", |
|
|
120 |
" <td>2</td>\n", |
|
|
121 |
" <td>1</td>\n", |
|
|
122 |
" </tr>\n", |
|
|
123 |
" <tr>\n", |
|
|
124 |
" <th>4</th>\n", |
|
|
125 |
" <td>57</td>\n", |
|
|
126 |
" <td>0</td>\n", |
|
|
127 |
" <td>0</td>\n", |
|
|
128 |
" <td>120</td>\n", |
|
|
129 |
" <td>354</td>\n", |
|
|
130 |
" <td>0</td>\n", |
|
|
131 |
" <td>1</td>\n", |
|
|
132 |
" <td>163</td>\n", |
|
|
133 |
" <td>1</td>\n", |
|
|
134 |
" <td>0.6</td>\n", |
|
|
135 |
" <td>2</td>\n", |
|
|
136 |
" <td>0</td>\n", |
|
|
137 |
" <td>2</td>\n", |
|
|
138 |
" <td>1</td>\n", |
|
|
139 |
" </tr>\n", |
|
|
140 |
" <tr>\n", |
|
|
141 |
" <th>5</th>\n", |
|
|
142 |
" <td>57</td>\n", |
|
|
143 |
" <td>1</td>\n", |
|
|
144 |
" <td>0</td>\n", |
|
|
145 |
" <td>140</td>\n", |
|
|
146 |
" <td>192</td>\n", |
|
|
147 |
" <td>0</td>\n", |
|
|
148 |
" <td>1</td>\n", |
|
|
149 |
" <td>148</td>\n", |
|
|
150 |
" <td>0</td>\n", |
|
|
151 |
" <td>0.4</td>\n", |
|
|
152 |
" <td>1</td>\n", |
|
|
153 |
" <td>0</td>\n", |
|
|
154 |
" <td>1</td>\n", |
|
|
155 |
" <td>1</td>\n", |
|
|
156 |
" </tr>\n", |
|
|
157 |
" <tr>\n", |
|
|
158 |
" <th>6</th>\n", |
|
|
159 |
" <td>56</td>\n", |
|
|
160 |
" <td>0</td>\n", |
|
|
161 |
" <td>1</td>\n", |
|
|
162 |
" <td>140</td>\n", |
|
|
163 |
" <td>294</td>\n", |
|
|
164 |
" <td>0</td>\n", |
|
|
165 |
" <td>0</td>\n", |
|
|
166 |
" <td>153</td>\n", |
|
|
167 |
" <td>0</td>\n", |
|
|
168 |
" <td>1.3</td>\n", |
|
|
169 |
" <td>1</td>\n", |
|
|
170 |
" <td>0</td>\n", |
|
|
171 |
" <td>2</td>\n", |
|
|
172 |
" <td>1</td>\n", |
|
|
173 |
" </tr>\n", |
|
|
174 |
" <tr>\n", |
|
|
175 |
" <th>7</th>\n", |
|
|
176 |
" <td>44</td>\n", |
|
|
177 |
" <td>1</td>\n", |
|
|
178 |
" <td>1</td>\n", |
|
|
179 |
" <td>120</td>\n", |
|
|
180 |
" <td>263</td>\n", |
|
|
181 |
" <td>0</td>\n", |
|
|
182 |
" <td>1</td>\n", |
|
|
183 |
" <td>173</td>\n", |
|
|
184 |
" <td>0</td>\n", |
|
|
185 |
" <td>0.0</td>\n", |
|
|
186 |
" <td>2</td>\n", |
|
|
187 |
" <td>0</td>\n", |
|
|
188 |
" <td>3</td>\n", |
|
|
189 |
" <td>1</td>\n", |
|
|
190 |
" </tr>\n", |
|
|
191 |
" <tr>\n", |
|
|
192 |
" <th>8</th>\n", |
|
|
193 |
" <td>52</td>\n", |
|
|
194 |
" <td>1</td>\n", |
|
|
195 |
" <td>2</td>\n", |
|
|
196 |
" <td>172</td>\n", |
|
|
197 |
" <td>199</td>\n", |
|
|
198 |
" <td>1</td>\n", |
|
|
199 |
" <td>1</td>\n", |
|
|
200 |
" <td>162</td>\n", |
|
|
201 |
" <td>0</td>\n", |
|
|
202 |
" <td>0.5</td>\n", |
|
|
203 |
" <td>2</td>\n", |
|
|
204 |
" <td>0</td>\n", |
|
|
205 |
" <td>3</td>\n", |
|
|
206 |
" <td>1</td>\n", |
|
|
207 |
" </tr>\n", |
|
|
208 |
" <tr>\n", |
|
|
209 |
" <th>9</th>\n", |
|
|
210 |
" <td>57</td>\n", |
|
|
211 |
" <td>1</td>\n", |
|
|
212 |
" <td>2</td>\n", |
|
|
213 |
" <td>150</td>\n", |
|
|
214 |
" <td>168</td>\n", |
|
|
215 |
" <td>0</td>\n", |
|
|
216 |
" <td>1</td>\n", |
|
|
217 |
" <td>174</td>\n", |
|
|
218 |
" <td>0</td>\n", |
|
|
219 |
" <td>1.6</td>\n", |
|
|
220 |
" <td>2</td>\n", |
|
|
221 |
" <td>0</td>\n", |
|
|
222 |
" <td>2</td>\n", |
|
|
223 |
" <td>1</td>\n", |
|
|
224 |
" </tr>\n", |
|
|
225 |
" <tr>\n", |
|
|
226 |
" <th>10</th>\n", |
|
|
227 |
" <td>54</td>\n", |
|
|
228 |
" <td>1</td>\n", |
|
|
229 |
" <td>0</td>\n", |
|
|
230 |
" <td>140</td>\n", |
|
|
231 |
" <td>239</td>\n", |
|
|
232 |
" <td>0</td>\n", |
|
|
233 |
" <td>1</td>\n", |
|
|
234 |
" <td>160</td>\n", |
|
|
235 |
" <td>0</td>\n", |
|
|
236 |
" <td>1.2</td>\n", |
|
|
237 |
" <td>2</td>\n", |
|
|
238 |
" <td>0</td>\n", |
|
|
239 |
" <td>2</td>\n", |
|
|
240 |
" <td>1</td>\n", |
|
|
241 |
" </tr>\n", |
|
|
242 |
" <tr>\n", |
|
|
243 |
" <th>11</th>\n", |
|
|
244 |
" <td>48</td>\n", |
|
|
245 |
" <td>0</td>\n", |
|
|
246 |
" <td>2</td>\n", |
|
|
247 |
" <td>130</td>\n", |
|
|
248 |
" <td>275</td>\n", |
|
|
249 |
" <td>0</td>\n", |
|
|
250 |
" <td>1</td>\n", |
|
|
251 |
" <td>139</td>\n", |
|
|
252 |
" <td>0</td>\n", |
|
|
253 |
" <td>0.2</td>\n", |
|
|
254 |
" <td>2</td>\n", |
|
|
255 |
" <td>0</td>\n", |
|
|
256 |
" <td>2</td>\n", |
|
|
257 |
" <td>1</td>\n", |
|
|
258 |
" </tr>\n", |
|
|
259 |
" <tr>\n", |
|
|
260 |
" <th>12</th>\n", |
|
|
261 |
" <td>49</td>\n", |
|
|
262 |
" <td>1</td>\n", |
|
|
263 |
" <td>1</td>\n", |
|
|
264 |
" <td>130</td>\n", |
|
|
265 |
" <td>266</td>\n", |
|
|
266 |
" <td>0</td>\n", |
|
|
267 |
" <td>1</td>\n", |
|
|
268 |
" <td>171</td>\n", |
|
|
269 |
" <td>0</td>\n", |
|
|
270 |
" <td>0.6</td>\n", |
|
|
271 |
" <td>2</td>\n", |
|
|
272 |
" <td>0</td>\n", |
|
|
273 |
" <td>2</td>\n", |
|
|
274 |
" <td>1</td>\n", |
|
|
275 |
" </tr>\n", |
|
|
276 |
" <tr>\n", |
|
|
277 |
" <th>13</th>\n", |
|
|
278 |
" <td>64</td>\n", |
|
|
279 |
" <td>1</td>\n", |
|
|
280 |
" <td>3</td>\n", |
|
|
281 |
" <td>110</td>\n", |
|
|
282 |
" <td>211</td>\n", |
|
|
283 |
" <td>0</td>\n", |
|
|
284 |
" <td>0</td>\n", |
|
|
285 |
" <td>144</td>\n", |
|
|
286 |
" <td>1</td>\n", |
|
|
287 |
" <td>1.8</td>\n", |
|
|
288 |
" <td>1</td>\n", |
|
|
289 |
" <td>0</td>\n", |
|
|
290 |
" <td>2</td>\n", |
|
|
291 |
" <td>1</td>\n", |
|
|
292 |
" </tr>\n", |
|
|
293 |
" <tr>\n", |
|
|
294 |
" <th>14</th>\n", |
|
|
295 |
" <td>58</td>\n", |
|
|
296 |
" <td>0</td>\n", |
|
|
297 |
" <td>3</td>\n", |
|
|
298 |
" <td>150</td>\n", |
|
|
299 |
" <td>283</td>\n", |
|
|
300 |
" <td>1</td>\n", |
|
|
301 |
" <td>0</td>\n", |
|
|
302 |
" <td>162</td>\n", |
|
|
303 |
" <td>0</td>\n", |
|
|
304 |
" <td>1.0</td>\n", |
|
|
305 |
" <td>2</td>\n", |
|
|
306 |
" <td>0</td>\n", |
|
|
307 |
" <td>2</td>\n", |
|
|
308 |
" <td>1</td>\n", |
|
|
309 |
" </tr>\n", |
|
|
310 |
" </tbody>\n", |
|
|
311 |
"</table>\n", |
|
|
312 |
"</div>" |
|
|
313 |
], |
|
|
314 |
"text/plain": [ |
|
|
315 |
" age sex cp trestbps chol fbs restecg thalach exang oldpeak \\\n", |
|
|
316 |
"0 63 1 3 145 233 1 0 150 0 2.3 \n", |
|
|
317 |
"1 37 1 2 130 250 0 1 187 0 3.5 \n", |
|
|
318 |
"2 41 0 1 130 204 0 0 172 0 1.4 \n", |
|
|
319 |
"3 56 1 1 120 236 0 1 178 0 0.8 \n", |
|
|
320 |
"4 57 0 0 120 354 0 1 163 1 0.6 \n", |
|
|
321 |
"5 57 1 0 140 192 0 1 148 0 0.4 \n", |
|
|
322 |
"6 56 0 1 140 294 0 0 153 0 1.3 \n", |
|
|
323 |
"7 44 1 1 120 263 0 1 173 0 0.0 \n", |
|
|
324 |
"8 52 1 2 172 199 1 1 162 0 0.5 \n", |
|
|
325 |
"9 57 1 2 150 168 0 1 174 0 1.6 \n", |
|
|
326 |
"10 54 1 0 140 239 0 1 160 0 1.2 \n", |
|
|
327 |
"11 48 0 2 130 275 0 1 139 0 0.2 \n", |
|
|
328 |
"12 49 1 1 130 266 0 1 171 0 0.6 \n", |
|
|
329 |
"13 64 1 3 110 211 0 0 144 1 1.8 \n", |
|
|
330 |
"14 58 0 3 150 283 1 0 162 0 1.0 \n", |
|
|
331 |
"\n", |
|
|
332 |
" slope ca thal target \n", |
|
|
333 |
"0 0 0 1 1 \n", |
|
|
334 |
"1 0 0 2 1 \n", |
|
|
335 |
"2 2 0 2 1 \n", |
|
|
336 |
"3 2 0 2 1 \n", |
|
|
337 |
"4 2 0 2 1 \n", |
|
|
338 |
"5 1 0 1 1 \n", |
|
|
339 |
"6 1 0 2 1 \n", |
|
|
340 |
"7 2 0 3 1 \n", |
|
|
341 |
"8 2 0 3 1 \n", |
|
|
342 |
"9 2 0 2 1 \n", |
|
|
343 |
"10 2 0 2 1 \n", |
|
|
344 |
"11 2 0 2 1 \n", |
|
|
345 |
"12 2 0 2 1 \n", |
|
|
346 |
"13 1 0 2 1 \n", |
|
|
347 |
"14 2 0 2 1 " |
|
|
348 |
] |
|
|
349 |
}, |
|
|
350 |
"execution_count": 1, |
|
|
351 |
"metadata": {}, |
|
|
352 |
"output_type": "execute_result" |
|
|
353 |
} |
|
|
354 |
], |
|
|
355 |
"source": [ |
|
|
356 |
"\n", |
|
|
357 |
"import numpy as np\n", |
|
|
358 |
"import pandas as pd\n", |
|
|
359 |
"from sklearn.model_selection import train_test_split\n", |
|
|
360 |
"from sklearn.linear_model import LogisticRegression\n", |
|
|
361 |
"from sklearn.metrics import accuracy_score\n", |
|
|
362 |
"\n", |
|
|
363 |
"\n", |
|
|
364 |
"df= pd.read_csv(r'C:\\Users\\Pranshu Saini\\Desktop\\disease-prediction-main\\docpat\\datasets\\heart.csv')\n", |
|
|
365 |
"df.head(15)\n" |
|
|
366 |
] |
|
|
367 |
}, |
|
|
368 |
{ |
|
|
369 |
"cell_type": "code", |
|
|
370 |
"execution_count": 2, |
|
|
371 |
"id": "7bd28756", |
|
|
372 |
"metadata": {}, |
|
|
373 |
"outputs": [ |
|
|
374 |
{ |
|
|
375 |
"data": { |
|
|
376 |
"text/plain": [ |
|
|
377 |
"(303, 14)" |
|
|
378 |
] |
|
|
379 |
}, |
|
|
380 |
"execution_count": 2, |
|
|
381 |
"metadata": {}, |
|
|
382 |
"output_type": "execute_result" |
|
|
383 |
} |
|
|
384 |
], |
|
|
385 |
"source": [ |
|
|
386 |
"df.shape" |
|
|
387 |
] |
|
|
388 |
}, |
|
|
389 |
{ |
|
|
390 |
"cell_type": "code", |
|
|
391 |
"execution_count": 3, |
|
|
392 |
"id": "3244edd5-3dd2-47f9-85da-b9cc26fed0d7", |
|
|
393 |
"metadata": {}, |
|
|
394 |
"outputs": [ |
|
|
395 |
{ |
|
|
396 |
"data": { |
|
|
397 |
"text/plain": [ |
|
|
398 |
"age 0\n", |
|
|
399 |
"sex 0\n", |
|
|
400 |
"cp 0\n", |
|
|
401 |
"trestbps 0\n", |
|
|
402 |
"chol 0\n", |
|
|
403 |
"fbs 0\n", |
|
|
404 |
"restecg 0\n", |
|
|
405 |
"thalach 0\n", |
|
|
406 |
"exang 0\n", |
|
|
407 |
"oldpeak 0\n", |
|
|
408 |
"slope 0\n", |
|
|
409 |
"ca 0\n", |
|
|
410 |
"thal 0\n", |
|
|
411 |
"target 0\n", |
|
|
412 |
"dtype: int64" |
|
|
413 |
] |
|
|
414 |
}, |
|
|
415 |
"execution_count": 3, |
|
|
416 |
"metadata": {}, |
|
|
417 |
"output_type": "execute_result" |
|
|
418 |
} |
|
|
419 |
], |
|
|
420 |
"source": [ |
|
|
421 |
"df.isna().sum()" |
|
|
422 |
] |
|
|
423 |
}, |
|
|
424 |
{ |
|
|
425 |
"cell_type": "code", |
|
|
426 |
"execution_count": 4, |
|
|
427 |
"id": "348dde1b-1ff9-4d98-91a9-29688f5b0933", |
|
|
428 |
"metadata": {}, |
|
|
429 |
"outputs": [ |
|
|
430 |
{ |
|
|
431 |
"name": "stdout", |
|
|
432 |
"output_type": "stream", |
|
|
433 |
"text": [ |
|
|
434 |
"The reduced dataframe has 14 columns.\n" |
|
|
435 |
] |
|
|
436 |
} |
|
|
437 |
], |
|
|
438 |
"source": [ |
|
|
439 |
"# removing highly correlated features\n", |
|
|
440 |
"\n", |
|
|
441 |
"corr_matrix = df.corr().abs() \n", |
|
|
442 |
"\n", |
|
|
443 |
"mask = np.triu(np.ones_like(corr_matrix, dtype = bool))\n", |
|
|
444 |
"tri_df = corr_matrix.mask(mask)\n", |
|
|
445 |
"\n", |
|
|
446 |
"to_drop = [x for x in tri_df.columns if any(tri_df[x] > 0.92)]\n", |
|
|
447 |
"\n", |
|
|
448 |
"df = df.drop(to_drop, axis = 1)\n", |
|
|
449 |
"\n", |
|
|
450 |
"print(f\"The reduced dataframe has {df.shape[1]} columns.\")" |
|
|
451 |
] |
|
|
452 |
}, |
|
|
453 |
{ |
|
|
454 |
"cell_type": "code", |
|
|
455 |
"execution_count": 5, |
|
|
456 |
"id": "16a87f6e", |
|
|
457 |
"metadata": {}, |
|
|
458 |
"outputs": [ |
|
|
459 |
{ |
|
|
460 |
"data": { |
|
|
461 |
"text/plain": [ |
|
|
462 |
"(303, 14)" |
|
|
463 |
] |
|
|
464 |
}, |
|
|
465 |
"execution_count": 5, |
|
|
466 |
"metadata": {}, |
|
|
467 |
"output_type": "execute_result" |
|
|
468 |
} |
|
|
469 |
], |
|
|
470 |
"source": [ |
|
|
471 |
"df.shape" |
|
|
472 |
] |
|
|
473 |
}, |
|
|
474 |
{ |
|
|
475 |
"cell_type": "code", |
|
|
476 |
"execution_count": 6, |
|
|
477 |
"id": "ade36649-a20a-4bf2-8368-64f70cd000f2", |
|
|
478 |
"metadata": {}, |
|
|
479 |
"outputs": [ |
|
|
480 |
{ |
|
|
481 |
"name": "stdout", |
|
|
482 |
"output_type": "stream", |
|
|
483 |
"text": [ |
|
|
484 |
"(303, 13) (242, 13) (61, 13)\n" |
|
|
485 |
] |
|
|
486 |
} |
|
|
487 |
], |
|
|
488 |
"source": [ |
|
|
489 |
"A = df.drop(columns='target', axis=1)\n", |
|
|
490 |
"B = df['target']\n", |
|
|
491 |
"A_training, A_testing, B_training, B_testing = train_test_split(A, B, test_size=0.2, stratify=B, random_state=2)\n", |
|
|
492 |
"\n", |
|
|
493 |
"print(A.shape, A_training.shape, A_testing.shape)" |
|
|
494 |
] |
|
|
495 |
}, |
|
|
496 |
{ |
|
|
497 |
"cell_type": "markdown", |
|
|
498 |
"id": "34f600fd-1faf-4a62-8aba-9a6d0fa38644", |
|
|
499 |
"metadata": {}, |
|
|
500 |
"source": [ |
|
|
501 |
"LogisticRegression" |
|
|
502 |
] |
|
|
503 |
}, |
|
|
504 |
{ |
|
|
505 |
"cell_type": "code", |
|
|
506 |
"execution_count": 7, |
|
|
507 |
"id": "fce2ced2-6375-4077-921e-2f568056fffe", |
|
|
508 |
"metadata": {}, |
|
|
509 |
"outputs": [ |
|
|
510 |
{ |
|
|
511 |
"name": "stdout", |
|
|
512 |
"output_type": "stream", |
|
|
513 |
"text": [ |
|
|
514 |
"0.8512396694214877\n", |
|
|
515 |
"0.819672131147541\n" |
|
|
516 |
] |
|
|
517 |
}, |
|
|
518 |
{ |
|
|
519 |
"name": "stderr", |
|
|
520 |
"output_type": "stream", |
|
|
521 |
"text": [ |
|
|
522 |
"c:\\Users\\Pranshu Saini\\AppData\\Local\\Programs\\Python\\Python312\\Lib\\site-packages\\sklearn\\linear_model\\_logistic.py:469: ConvergenceWarning: lbfgs failed to converge (status=1):\n", |
|
|
523 |
"STOP: TOTAL NO. of ITERATIONS REACHED LIMIT.\n", |
|
|
524 |
"\n", |
|
|
525 |
"Increase the number of iterations (max_iter) or scale the data as shown in:\n", |
|
|
526 |
" https://scikit-learn.org/stable/modules/preprocessing.html\n", |
|
|
527 |
"Please also refer to the documentation for alternative solver options:\n", |
|
|
528 |
" https://scikit-learn.org/stable/modules/linear_model.html#logistic-regression\n", |
|
|
529 |
" n_iter_i = _check_optimize_result(\n" |
|
|
530 |
] |
|
|
531 |
} |
|
|
532 |
], |
|
|
533 |
"source": [ |
|
|
534 |
"# fitting data to model\n", |
|
|
535 |
"\n", |
|
|
536 |
"from sklearn.linear_model import LogisticRegression\n", |
|
|
537 |
"\n", |
|
|
538 |
"log_reg = LogisticRegression()\n", |
|
|
539 |
"log_reg.fit(A_training, B_training)\n", |
|
|
540 |
"B_pred = log_reg.predict(A_testing)\n", |
|
|
541 |
"# accuracy score\n", |
|
|
542 |
"\n", |
|
|
543 |
"from sklearn.metrics import accuracy_score, confusion_matrix, classification_report\n", |
|
|
544 |
"\n", |
|
|
545 |
"print(accuracy_score(B_training, log_reg.predict(A_training)))\n", |
|
|
546 |
"\n", |
|
|
547 |
"log_reg_acc = accuracy_score(B_testing, log_reg.predict(A_testing))\n", |
|
|
548 |
"print(log_reg_acc)" |
|
|
549 |
] |
|
|
550 |
}, |
|
|
551 |
{ |
|
|
552 |
"cell_type": "markdown", |
|
|
553 |
"id": "f1a6ab2c-fc10-4f0b-8b07-1e01f8ce1243", |
|
|
554 |
"metadata": {}, |
|
|
555 |
"source": [ |
|
|
556 |
"K Neighbors Classifier (KNN)\n" |
|
|
557 |
] |
|
|
558 |
}, |
|
|
559 |
{ |
|
|
560 |
"cell_type": "code", |
|
|
561 |
"execution_count": 8, |
|
|
562 |
"id": "f8aecca7-018d-41ba-bb3c-2a96cf73b007", |
|
|
563 |
"metadata": {}, |
|
|
564 |
"outputs": [ |
|
|
565 |
{ |
|
|
566 |
"name": "stdout", |
|
|
567 |
"output_type": "stream", |
|
|
568 |
"text": [ |
|
|
569 |
"0.78099173553719\n", |
|
|
570 |
"0.6229508196721312\n" |
|
|
571 |
] |
|
|
572 |
} |
|
|
573 |
], |
|
|
574 |
"source": [ |
|
|
575 |
"from sklearn.neighbors import KNeighborsClassifier\n", |
|
|
576 |
"\n", |
|
|
577 |
"knn = KNeighborsClassifier()\n", |
|
|
578 |
"knn.fit(A_training, B_training)\n", |
|
|
579 |
"# model predictions \n", |
|
|
580 |
"\n", |
|
|
581 |
"B_pred = knn.predict(A_testing)\n", |
|
|
582 |
"# accuracy score\n", |
|
|
583 |
"\n", |
|
|
584 |
"print(accuracy_score(B_training, knn.predict(A_training)))\n", |
|
|
585 |
"\n", |
|
|
586 |
"knn_acc = accuracy_score(B_testing, knn.predict(A_testing))\n", |
|
|
587 |
"print(knn_acc)" |
|
|
588 |
] |
|
|
589 |
}, |
|
|
590 |
{ |
|
|
591 |
"cell_type": "markdown", |
|
|
592 |
"id": "dd05e4cf-6aaf-468e-9eef-6f1b27d99560", |
|
|
593 |
"metadata": {}, |
|
|
594 |
"source": [ |
|
|
595 |
"Support Vector Machine (SVM)" |
|
|
596 |
] |
|
|
597 |
}, |
|
|
598 |
{ |
|
|
599 |
"cell_type": "code", |
|
|
600 |
"execution_count": 9, |
|
|
601 |
"id": "35cc692b-d57f-4738-badf-5fd6c02c2889", |
|
|
602 |
"metadata": {}, |
|
|
603 |
"outputs": [ |
|
|
604 |
{ |
|
|
605 |
"data": { |
|
|
606 |
"text/plain": [ |
|
|
607 |
"{'C': 20, 'gamma': 0.0001}" |
|
|
608 |
] |
|
|
609 |
}, |
|
|
610 |
"execution_count": 9, |
|
|
611 |
"metadata": {}, |
|
|
612 |
"output_type": "execute_result" |
|
|
613 |
} |
|
|
614 |
], |
|
|
615 |
"source": [ |
|
|
616 |
"from sklearn.svm import SVC\n", |
|
|
617 |
"from sklearn.model_selection import GridSearchCV\n", |
|
|
618 |
"\n", |
|
|
619 |
"svc = SVC(probability=True)\n", |
|
|
620 |
"parameters = {\n", |
|
|
621 |
" 'gamma' : [0.0001, 0.001, 0.01, 0.1],\n", |
|
|
622 |
" 'C' : [0.01, 0.05, 0.5, 0.1, 1, 10, 15, 20]\n", |
|
|
623 |
"}\n", |
|
|
624 |
"\n", |
|
|
625 |
"grid_search = GridSearchCV(svc, parameters)\n", |
|
|
626 |
"grid_search.fit(A_training, B_training)\n", |
|
|
627 |
"# best parameters\n", |
|
|
628 |
"\n", |
|
|
629 |
"grid_search.best_params_\n", |
|
|
630 |
"\n" |
|
|
631 |
] |
|
|
632 |
}, |
|
|
633 |
{ |
|
|
634 |
"cell_type": "code", |
|
|
635 |
"execution_count": 10, |
|
|
636 |
"id": "cb090811-a42c-47ec-b7c7-43889430b93d", |
|
|
637 |
"metadata": {}, |
|
|
638 |
"outputs": [ |
|
|
639 |
{ |
|
|
640 |
"data": { |
|
|
641 |
"text/plain": [ |
|
|
642 |
"0.6981292517006803" |
|
|
643 |
] |
|
|
644 |
}, |
|
|
645 |
"execution_count": 10, |
|
|
646 |
"metadata": {}, |
|
|
647 |
"output_type": "execute_result" |
|
|
648 |
} |
|
|
649 |
], |
|
|
650 |
"source": [ |
|
|
651 |
"# best score \n", |
|
|
652 |
"\n", |
|
|
653 |
"grid_search.best_score_\n", |
|
|
654 |
"\n" |
|
|
655 |
] |
|
|
656 |
}, |
|
|
657 |
{ |
|
|
658 |
"cell_type": "code", |
|
|
659 |
"execution_count": 11, |
|
|
660 |
"id": "639e3132-7346-40d5-becf-6d230a9004fb", |
|
|
661 |
"metadata": {}, |
|
|
662 |
"outputs": [ |
|
|
663 |
{ |
|
|
664 |
"name": "stdout", |
|
|
665 |
"output_type": "stream", |
|
|
666 |
"text": [ |
|
|
667 |
"1.0\n", |
|
|
668 |
"0.5409836065573771\n", |
|
|
669 |
" precision recall f1-score support\n", |
|
|
670 |
"\n", |
|
|
671 |
" 0 0.50 0.43 0.46 28\n", |
|
|
672 |
" 1 0.57 0.64 0.60 33\n", |
|
|
673 |
"\n", |
|
|
674 |
" accuracy 0.54 61\n", |
|
|
675 |
" macro avg 0.53 0.53 0.53 61\n", |
|
|
676 |
"weighted avg 0.54 0.54 0.54 61\n", |
|
|
677 |
"\n" |
|
|
678 |
] |
|
|
679 |
} |
|
|
680 |
], |
|
|
681 |
"source": [ |
|
|
682 |
"svc = SVC(C = 10, gamma = 0.01, probability=True)\n", |
|
|
683 |
"svc.fit(A_training, B_training)\n", |
|
|
684 |
"# model predictions \n", |
|
|
685 |
"\n", |
|
|
686 |
"B_pred = svc.predict(A_testing)\n", |
|
|
687 |
"# accuracy score\n", |
|
|
688 |
"\n", |
|
|
689 |
"print(accuracy_score(B_training, svc.predict(A_training)))\n", |
|
|
690 |
"\n", |
|
|
691 |
"svc_acc = accuracy_score(B_testing, svc.predict(A_testing))\n", |
|
|
692 |
"print(svc_acc)\n", |
|
|
693 |
"# classification report\n", |
|
|
694 |
"\n", |
|
|
695 |
"print(classification_report(B_testing, B_pred))" |
|
|
696 |
] |
|
|
697 |
}, |
|
|
698 |
{ |
|
|
699 |
"cell_type": "markdown", |
|
|
700 |
"id": "0e3059b1-2e79-46bd-9195-98cbd044b75c", |
|
|
701 |
"metadata": {}, |
|
|
702 |
"source": [ |
|
|
703 |
"DECISION TREE" |
|
|
704 |
] |
|
|
705 |
}, |
|
|
706 |
{ |
|
|
707 |
"cell_type": "code", |
|
|
708 |
"execution_count": 12, |
|
|
709 |
"id": "79b6cc36-eab3-4502-861f-0c4576170ffd", |
|
|
710 |
"metadata": {}, |
|
|
711 |
"outputs": [ |
|
|
712 |
{ |
|
|
713 |
"name": "stdout", |
|
|
714 |
"output_type": "stream", |
|
|
715 |
"text": [ |
|
|
716 |
"Fitting 5 folds for each of 8640 candidates, totalling 43200 fits\n" |
|
|
717 |
] |
|
|
718 |
}, |
|
|
719 |
{ |
|
|
720 |
"data": { |
|
|
721 |
"text/html": [ |
|
|
722 |
"<style>#sk-container-id-1 {\n", |
|
|
723 |
" /* Definition of color scheme common for light and dark mode */\n", |
|
|
724 |
" --sklearn-color-text: black;\n", |
|
|
725 |
" --sklearn-color-line: gray;\n", |
|
|
726 |
" /* Definition of color scheme for unfitted estimators */\n", |
|
|
727 |
" --sklearn-color-unfitted-level-0: #fff5e6;\n", |
|
|
728 |
" --sklearn-color-unfitted-level-1: #f6e4d2;\n", |
|
|
729 |
" --sklearn-color-unfitted-level-2: #ffe0b3;\n", |
|
|
730 |
" --sklearn-color-unfitted-level-3: chocolate;\n", |
|
|
731 |
" /* Definition of color scheme for fitted estimators */\n", |
|
|
732 |
" --sklearn-color-fitted-level-0: #f0f8ff;\n", |
|
|
733 |
" --sklearn-color-fitted-level-1: #d4ebff;\n", |
|
|
734 |
" --sklearn-color-fitted-level-2: #b3dbfd;\n", |
|
|
735 |
" --sklearn-color-fitted-level-3: cornflowerblue;\n", |
|
|
736 |
"\n", |
|
|
737 |
" /* Specific color for light theme */\n", |
|
|
738 |
" --sklearn-color-text-on-default-background: var(--sg-text-color, var(--theme-code-foreground, var(--jp-content-font-color1, black)));\n", |
|
|
739 |
" --sklearn-color-background: var(--sg-background-color, var(--theme-background, var(--jp-layout-color0, white)));\n", |
|
|
740 |
" --sklearn-color-border-box: var(--sg-text-color, var(--theme-code-foreground, var(--jp-content-font-color1, black)));\n", |
|
|
741 |
" --sklearn-color-icon: #696969;\n", |
|
|
742 |
"\n", |
|
|
743 |
" @media (prefers-color-scheme: dark) {\n", |
|
|
744 |
" /* Redefinition of color scheme for dark theme */\n", |
|
|
745 |
" --sklearn-color-text-on-default-background: var(--sg-text-color, var(--theme-code-foreground, var(--jp-content-font-color1, white)));\n", |
|
|
746 |
" --sklearn-color-background: var(--sg-background-color, var(--theme-background, var(--jp-layout-color0, #111)));\n", |
|
|
747 |
" --sklearn-color-border-box: var(--sg-text-color, var(--theme-code-foreground, var(--jp-content-font-color1, white)));\n", |
|
|
748 |
" --sklearn-color-icon: #878787;\n", |
|
|
749 |
" }\n", |
|
|
750 |
"}\n", |
|
|
751 |
"\n", |
|
|
752 |
"#sk-container-id-1 {\n", |
|
|
753 |
" color: var(--sklearn-color-text);\n", |
|
|
754 |
"}\n", |
|
|
755 |
"\n", |
|
|
756 |
"#sk-container-id-1 pre {\n", |
|
|
757 |
" padding: 0;\n", |
|
|
758 |
"}\n", |
|
|
759 |
"\n", |
|
|
760 |
"#sk-container-id-1 input.sk-hidden--visually {\n", |
|
|
761 |
" border: 0;\n", |
|
|
762 |
" clip: rect(1px 1px 1px 1px);\n", |
|
|
763 |
" clip: rect(1px, 1px, 1px, 1px);\n", |
|
|
764 |
" height: 1px;\n", |
|
|
765 |
" margin: -1px;\n", |
|
|
766 |
" overflow: hidden;\n", |
|
|
767 |
" padding: 0;\n", |
|
|
768 |
" position: absolute;\n", |
|
|
769 |
" width: 1px;\n", |
|
|
770 |
"}\n", |
|
|
771 |
"\n", |
|
|
772 |
"#sk-container-id-1 div.sk-dashed-wrapped {\n", |
|
|
773 |
" border: 1px dashed var(--sklearn-color-line);\n", |
|
|
774 |
" margin: 0 0.4em 0.5em 0.4em;\n", |
|
|
775 |
" box-sizing: border-box;\n", |
|
|
776 |
" padding-bottom: 0.4em;\n", |
|
|
777 |
" background-color: var(--sklearn-color-background);\n", |
|
|
778 |
"}\n", |
|
|
779 |
"\n", |
|
|
780 |
"#sk-container-id-1 div.sk-container {\n", |
|
|
781 |
" /* jupyter's `normalize.less` sets `[hidden] { display: none; }`\n", |
|
|
782 |
" but bootstrap.min.css set `[hidden] { display: none !important; }`\n", |
|
|
783 |
" so we also need the `!important` here to be able to override the\n", |
|
|
784 |
" default hidden behavior on the sphinx rendered scikit-learn.org.\n", |
|
|
785 |
" See: https://github.com/scikit-learn/scikit-learn/issues/21755 */\n", |
|
|
786 |
" display: inline-block !important;\n", |
|
|
787 |
" position: relative;\n", |
|
|
788 |
"}\n", |
|
|
789 |
"\n", |
|
|
790 |
"#sk-container-id-1 div.sk-text-repr-fallback {\n", |
|
|
791 |
" display: none;\n", |
|
|
792 |
"}\n", |
|
|
793 |
"\n", |
|
|
794 |
"div.sk-parallel-item,\n", |
|
|
795 |
"div.sk-serial,\n", |
|
|
796 |
"div.sk-item {\n", |
|
|
797 |
" /* draw centered vertical line to link estimators */\n", |
|
|
798 |
" background-image: linear-gradient(var(--sklearn-color-text-on-default-background), var(--sklearn-color-text-on-default-background));\n", |
|
|
799 |
" background-size: 2px 100%;\n", |
|
|
800 |
" background-repeat: no-repeat;\n", |
|
|
801 |
" background-position: center center;\n", |
|
|
802 |
"}\n", |
|
|
803 |
"\n", |
|
|
804 |
"/* Parallel-specific style estimator block */\n", |
|
|
805 |
"\n", |
|
|
806 |
"#sk-container-id-1 div.sk-parallel-item::after {\n", |
|
|
807 |
" content: \"\";\n", |
|
|
808 |
" width: 100%;\n", |
|
|
809 |
" border-bottom: 2px solid var(--sklearn-color-text-on-default-background);\n", |
|
|
810 |
" flex-grow: 1;\n", |
|
|
811 |
"}\n", |
|
|
812 |
"\n", |
|
|
813 |
"#sk-container-id-1 div.sk-parallel {\n", |
|
|
814 |
" display: flex;\n", |
|
|
815 |
" align-items: stretch;\n", |
|
|
816 |
" justify-content: center;\n", |
|
|
817 |
" background-color: var(--sklearn-color-background);\n", |
|
|
818 |
" position: relative;\n", |
|
|
819 |
"}\n", |
|
|
820 |
"\n", |
|
|
821 |
"#sk-container-id-1 div.sk-parallel-item {\n", |
|
|
822 |
" display: flex;\n", |
|
|
823 |
" flex-direction: column;\n", |
|
|
824 |
"}\n", |
|
|
825 |
"\n", |
|
|
826 |
"#sk-container-id-1 div.sk-parallel-item:first-child::after {\n", |
|
|
827 |
" align-self: flex-end;\n", |
|
|
828 |
" width: 50%;\n", |
|
|
829 |
"}\n", |
|
|
830 |
"\n", |
|
|
831 |
"#sk-container-id-1 div.sk-parallel-item:last-child::after {\n", |
|
|
832 |
" align-self: flex-start;\n", |
|
|
833 |
" width: 50%;\n", |
|
|
834 |
"}\n", |
|
|
835 |
"\n", |
|
|
836 |
"#sk-container-id-1 div.sk-parallel-item:only-child::after {\n", |
|
|
837 |
" width: 0;\n", |
|
|
838 |
"}\n", |
|
|
839 |
"\n", |
|
|
840 |
"/* Serial-specific style estimator block */\n", |
|
|
841 |
"\n", |
|
|
842 |
"#sk-container-id-1 div.sk-serial {\n", |
|
|
843 |
" display: flex;\n", |
|
|
844 |
" flex-direction: column;\n", |
|
|
845 |
" align-items: center;\n", |
|
|
846 |
" background-color: var(--sklearn-color-background);\n", |
|
|
847 |
" padding-right: 1em;\n", |
|
|
848 |
" padding-left: 1em;\n", |
|
|
849 |
"}\n", |
|
|
850 |
"\n", |
|
|
851 |
"\n", |
|
|
852 |
"/* Toggleable style: style used for estimator/Pipeline/ColumnTransformer box that is\n", |
|
|
853 |
"clickable and can be expanded/collapsed.\n", |
|
|
854 |
"- Pipeline and ColumnTransformer use this feature and define the default style\n", |
|
|
855 |
"- Estimators will overwrite some part of the style using the `sk-estimator` class\n", |
|
|
856 |
"*/\n", |
|
|
857 |
"\n", |
|
|
858 |
"/* Pipeline and ColumnTransformer style (default) */\n", |
|
|
859 |
"\n", |
|
|
860 |
"#sk-container-id-1 div.sk-toggleable {\n", |
|
|
861 |
" /* Default theme specific background. It is overwritten whether we have a\n", |
|
|
862 |
" specific estimator or a Pipeline/ColumnTransformer */\n", |
|
|
863 |
" background-color: var(--sklearn-color-background);\n", |
|
|
864 |
"}\n", |
|
|
865 |
"\n", |
|
|
866 |
"/* Toggleable label */\n", |
|
|
867 |
"#sk-container-id-1 label.sk-toggleable__label {\n", |
|
|
868 |
" cursor: pointer;\n", |
|
|
869 |
" display: block;\n", |
|
|
870 |
" width: 100%;\n", |
|
|
871 |
" margin-bottom: 0;\n", |
|
|
872 |
" padding: 0.5em;\n", |
|
|
873 |
" box-sizing: border-box;\n", |
|
|
874 |
" text-align: center;\n", |
|
|
875 |
"}\n", |
|
|
876 |
"\n", |
|
|
877 |
"#sk-container-id-1 label.sk-toggleable__label-arrow:before {\n", |
|
|
878 |
" /* Arrow on the left of the label */\n", |
|
|
879 |
" content: \"▸\";\n", |
|
|
880 |
" float: left;\n", |
|
|
881 |
" margin-right: 0.25em;\n", |
|
|
882 |
" color: var(--sklearn-color-icon);\n", |
|
|
883 |
"}\n", |
|
|
884 |
"\n", |
|
|
885 |
"#sk-container-id-1 label.sk-toggleable__label-arrow:hover:before {\n", |
|
|
886 |
" color: var(--sklearn-color-text);\n", |
|
|
887 |
"}\n", |
|
|
888 |
"\n", |
|
|
889 |
"/* Toggleable content - dropdown */\n", |
|
|
890 |
"\n", |
|
|
891 |
"#sk-container-id-1 div.sk-toggleable__content {\n", |
|
|
892 |
" max-height: 0;\n", |
|
|
893 |
" max-width: 0;\n", |
|
|
894 |
" overflow: hidden;\n", |
|
|
895 |
" text-align: left;\n", |
|
|
896 |
" /* unfitted */\n", |
|
|
897 |
" background-color: var(--sklearn-color-unfitted-level-0);\n", |
|
|
898 |
"}\n", |
|
|
899 |
"\n", |
|
|
900 |
"#sk-container-id-1 div.sk-toggleable__content.fitted {\n", |
|
|
901 |
" /* fitted */\n", |
|
|
902 |
" background-color: var(--sklearn-color-fitted-level-0);\n", |
|
|
903 |
"}\n", |
|
|
904 |
"\n", |
|
|
905 |
"#sk-container-id-1 div.sk-toggleable__content pre {\n", |
|
|
906 |
" margin: 0.2em;\n", |
|
|
907 |
" border-radius: 0.25em;\n", |
|
|
908 |
" color: var(--sklearn-color-text);\n", |
|
|
909 |
" /* unfitted */\n", |
|
|
910 |
" background-color: var(--sklearn-color-unfitted-level-0);\n", |
|
|
911 |
"}\n", |
|
|
912 |
"\n", |
|
|
913 |
"#sk-container-id-1 div.sk-toggleable__content.fitted pre {\n", |
|
|
914 |
" /* unfitted */\n", |
|
|
915 |
" background-color: var(--sklearn-color-fitted-level-0);\n", |
|
|
916 |
"}\n", |
|
|
917 |
"\n", |
|
|
918 |
"#sk-container-id-1 input.sk-toggleable__control:checked~div.sk-toggleable__content {\n", |
|
|
919 |
" /* Expand drop-down */\n", |
|
|
920 |
" max-height: 200px;\n", |
|
|
921 |
" max-width: 100%;\n", |
|
|
922 |
" overflow: auto;\n", |
|
|
923 |
"}\n", |
|
|
924 |
"\n", |
|
|
925 |
"#sk-container-id-1 input.sk-toggleable__control:checked~label.sk-toggleable__label-arrow:before {\n", |
|
|
926 |
" content: \"▾\";\n", |
|
|
927 |
"}\n", |
|
|
928 |
"\n", |
|
|
929 |
"/* Pipeline/ColumnTransformer-specific style */\n", |
|
|
930 |
"\n", |
|
|
931 |
"#sk-container-id-1 div.sk-label input.sk-toggleable__control:checked~label.sk-toggleable__label {\n", |
|
|
932 |
" color: var(--sklearn-color-text);\n", |
|
|
933 |
" background-color: var(--sklearn-color-unfitted-level-2);\n", |
|
|
934 |
"}\n", |
|
|
935 |
"\n", |
|
|
936 |
"#sk-container-id-1 div.sk-label.fitted input.sk-toggleable__control:checked~label.sk-toggleable__label {\n", |
|
|
937 |
" background-color: var(--sklearn-color-fitted-level-2);\n", |
|
|
938 |
"}\n", |
|
|
939 |
"\n", |
|
|
940 |
"/* Estimator-specific style */\n", |
|
|
941 |
"\n", |
|
|
942 |
"/* Colorize estimator box */\n", |
|
|
943 |
"#sk-container-id-1 div.sk-estimator input.sk-toggleable__control:checked~label.sk-toggleable__label {\n", |
|
|
944 |
" /* unfitted */\n", |
|
|
945 |
" background-color: var(--sklearn-color-unfitted-level-2);\n", |
|
|
946 |
"}\n", |
|
|
947 |
"\n", |
|
|
948 |
"#sk-container-id-1 div.sk-estimator.fitted input.sk-toggleable__control:checked~label.sk-toggleable__label {\n", |
|
|
949 |
" /* fitted */\n", |
|
|
950 |
" background-color: var(--sklearn-color-fitted-level-2);\n", |
|
|
951 |
"}\n", |
|
|
952 |
"\n", |
|
|
953 |
"#sk-container-id-1 div.sk-label label.sk-toggleable__label,\n", |
|
|
954 |
"#sk-container-id-1 div.sk-label label {\n", |
|
|
955 |
" /* The background is the default theme color */\n", |
|
|
956 |
" color: var(--sklearn-color-text-on-default-background);\n", |
|
|
957 |
"}\n", |
|
|
958 |
"\n", |
|
|
959 |
"/* On hover, darken the color of the background */\n", |
|
|
960 |
"#sk-container-id-1 div.sk-label:hover label.sk-toggleable__label {\n", |
|
|
961 |
" color: var(--sklearn-color-text);\n", |
|
|
962 |
" background-color: var(--sklearn-color-unfitted-level-2);\n", |
|
|
963 |
"}\n", |
|
|
964 |
"\n", |
|
|
965 |
"/* Label box, darken color on hover, fitted */\n", |
|
|
966 |
"#sk-container-id-1 div.sk-label.fitted:hover label.sk-toggleable__label.fitted {\n", |
|
|
967 |
" color: var(--sklearn-color-text);\n", |
|
|
968 |
" background-color: var(--sklearn-color-fitted-level-2);\n", |
|
|
969 |
"}\n", |
|
|
970 |
"\n", |
|
|
971 |
"/* Estimator label */\n", |
|
|
972 |
"\n", |
|
|
973 |
"#sk-container-id-1 div.sk-label label {\n", |
|
|
974 |
" font-family: monospace;\n", |
|
|
975 |
" font-weight: bold;\n", |
|
|
976 |
" display: inline-block;\n", |
|
|
977 |
" line-height: 1.2em;\n", |
|
|
978 |
"}\n", |
|
|
979 |
"\n", |
|
|
980 |
"#sk-container-id-1 div.sk-label-container {\n", |
|
|
981 |
" text-align: center;\n", |
|
|
982 |
"}\n", |
|
|
983 |
"\n", |
|
|
984 |
"/* Estimator-specific */\n", |
|
|
985 |
"#sk-container-id-1 div.sk-estimator {\n", |
|
|
986 |
" font-family: monospace;\n", |
|
|
987 |
" border: 1px dotted var(--sklearn-color-border-box);\n", |
|
|
988 |
" border-radius: 0.25em;\n", |
|
|
989 |
" box-sizing: border-box;\n", |
|
|
990 |
" margin-bottom: 0.5em;\n", |
|
|
991 |
" /* unfitted */\n", |
|
|
992 |
" background-color: var(--sklearn-color-unfitted-level-0);\n", |
|
|
993 |
"}\n", |
|
|
994 |
"\n", |
|
|
995 |
"#sk-container-id-1 div.sk-estimator.fitted {\n", |
|
|
996 |
" /* fitted */\n", |
|
|
997 |
" background-color: var(--sklearn-color-fitted-level-0);\n", |
|
|
998 |
"}\n", |
|
|
999 |
"\n", |
|
|
1000 |
"/* on hover */\n", |
|
|
1001 |
"#sk-container-id-1 div.sk-estimator:hover {\n", |
|
|
1002 |
" /* unfitted */\n", |
|
|
1003 |
" background-color: var(--sklearn-color-unfitted-level-2);\n", |
|
|
1004 |
"}\n", |
|
|
1005 |
"\n", |
|
|
1006 |
"#sk-container-id-1 div.sk-estimator.fitted:hover {\n", |
|
|
1007 |
" /* fitted */\n", |
|
|
1008 |
" background-color: var(--sklearn-color-fitted-level-2);\n", |
|
|
1009 |
"}\n", |
|
|
1010 |
"\n", |
|
|
1011 |
"/* Specification for estimator info (e.g. \"i\" and \"?\") */\n", |
|
|
1012 |
"\n", |
|
|
1013 |
"/* Common style for \"i\" and \"?\" */\n", |
|
|
1014 |
"\n", |
|
|
1015 |
".sk-estimator-doc-link,\n", |
|
|
1016 |
"a:link.sk-estimator-doc-link,\n", |
|
|
1017 |
"a:visited.sk-estimator-doc-link {\n", |
|
|
1018 |
" float: right;\n", |
|
|
1019 |
" font-size: smaller;\n", |
|
|
1020 |
" line-height: 1em;\n", |
|
|
1021 |
" font-family: monospace;\n", |
|
|
1022 |
" background-color: var(--sklearn-color-background);\n", |
|
|
1023 |
" border-radius: 1em;\n", |
|
|
1024 |
" height: 1em;\n", |
|
|
1025 |
" width: 1em;\n", |
|
|
1026 |
" text-decoration: none !important;\n", |
|
|
1027 |
" margin-left: 1ex;\n", |
|
|
1028 |
" /* unfitted */\n", |
|
|
1029 |
" border: var(--sklearn-color-unfitted-level-1) 1pt solid;\n", |
|
|
1030 |
" color: var(--sklearn-color-unfitted-level-1);\n", |
|
|
1031 |
"}\n", |
|
|
1032 |
"\n", |
|
|
1033 |
".sk-estimator-doc-link.fitted,\n", |
|
|
1034 |
"a:link.sk-estimator-doc-link.fitted,\n", |
|
|
1035 |
"a:visited.sk-estimator-doc-link.fitted {\n", |
|
|
1036 |
" /* fitted */\n", |
|
|
1037 |
" border: var(--sklearn-color-fitted-level-1) 1pt solid;\n", |
|
|
1038 |
" color: var(--sklearn-color-fitted-level-1);\n", |
|
|
1039 |
"}\n", |
|
|
1040 |
"\n", |
|
|
1041 |
"/* On hover */\n", |
|
|
1042 |
"div.sk-estimator:hover .sk-estimator-doc-link:hover,\n", |
|
|
1043 |
".sk-estimator-doc-link:hover,\n", |
|
|
1044 |
"div.sk-label-container:hover .sk-estimator-doc-link:hover,\n", |
|
|
1045 |
".sk-estimator-doc-link:hover {\n", |
|
|
1046 |
" /* unfitted */\n", |
|
|
1047 |
" background-color: var(--sklearn-color-unfitted-level-3);\n", |
|
|
1048 |
" color: var(--sklearn-color-background);\n", |
|
|
1049 |
" text-decoration: none;\n", |
|
|
1050 |
"}\n", |
|
|
1051 |
"\n", |
|
|
1052 |
"div.sk-estimator.fitted:hover .sk-estimator-doc-link.fitted:hover,\n", |
|
|
1053 |
".sk-estimator-doc-link.fitted:hover,\n", |
|
|
1054 |
"div.sk-label-container:hover .sk-estimator-doc-link.fitted:hover,\n", |
|
|
1055 |
".sk-estimator-doc-link.fitted:hover {\n", |
|
|
1056 |
" /* fitted */\n", |
|
|
1057 |
" background-color: var(--sklearn-color-fitted-level-3);\n", |
|
|
1058 |
" color: var(--sklearn-color-background);\n", |
|
|
1059 |
" text-decoration: none;\n", |
|
|
1060 |
"}\n", |
|
|
1061 |
"\n", |
|
|
1062 |
"/* Span, style for the box shown on hovering the info icon */\n", |
|
|
1063 |
".sk-estimator-doc-link span {\n", |
|
|
1064 |
" display: none;\n", |
|
|
1065 |
" z-index: 9999;\n", |
|
|
1066 |
" position: relative;\n", |
|
|
1067 |
" font-weight: normal;\n", |
|
|
1068 |
" right: .2ex;\n", |
|
|
1069 |
" padding: .5ex;\n", |
|
|
1070 |
" margin: .5ex;\n", |
|
|
1071 |
" width: min-content;\n", |
|
|
1072 |
" min-width: 20ex;\n", |
|
|
1073 |
" max-width: 50ex;\n", |
|
|
1074 |
" color: var(--sklearn-color-text);\n", |
|
|
1075 |
" box-shadow: 2pt 2pt 4pt #999;\n", |
|
|
1076 |
" /* unfitted */\n", |
|
|
1077 |
" background: var(--sklearn-color-unfitted-level-0);\n", |
|
|
1078 |
" border: .5pt solid var(--sklearn-color-unfitted-level-3);\n", |
|
|
1079 |
"}\n", |
|
|
1080 |
"\n", |
|
|
1081 |
".sk-estimator-doc-link.fitted span {\n", |
|
|
1082 |
" /* fitted */\n", |
|
|
1083 |
" background: var(--sklearn-color-fitted-level-0);\n", |
|
|
1084 |
" border: var(--sklearn-color-fitted-level-3);\n", |
|
|
1085 |
"}\n", |
|
|
1086 |
"\n", |
|
|
1087 |
".sk-estimator-doc-link:hover span {\n", |
|
|
1088 |
" display: block;\n", |
|
|
1089 |
"}\n", |
|
|
1090 |
"\n", |
|
|
1091 |
"/* \"?\"-specific style due to the `<a>` HTML tag */\n", |
|
|
1092 |
"\n", |
|
|
1093 |
"#sk-container-id-1 a.estimator_doc_link {\n", |
|
|
1094 |
" float: right;\n", |
|
|
1095 |
" font-size: 1rem;\n", |
|
|
1096 |
" line-height: 1em;\n", |
|
|
1097 |
" font-family: monospace;\n", |
|
|
1098 |
" background-color: var(--sklearn-color-background);\n", |
|
|
1099 |
" border-radius: 1rem;\n", |
|
|
1100 |
" height: 1rem;\n", |
|
|
1101 |
" width: 1rem;\n", |
|
|
1102 |
" text-decoration: none;\n", |
|
|
1103 |
" /* unfitted */\n", |
|
|
1104 |
" color: var(--sklearn-color-unfitted-level-1);\n", |
|
|
1105 |
" border: var(--sklearn-color-unfitted-level-1) 1pt solid;\n", |
|
|
1106 |
"}\n", |
|
|
1107 |
"\n", |
|
|
1108 |
"#sk-container-id-1 a.estimator_doc_link.fitted {\n", |
|
|
1109 |
" /* fitted */\n", |
|
|
1110 |
" border: var(--sklearn-color-fitted-level-1) 1pt solid;\n", |
|
|
1111 |
" color: var(--sklearn-color-fitted-level-1);\n", |
|
|
1112 |
"}\n", |
|
|
1113 |
"\n", |
|
|
1114 |
"/* On hover */\n", |
|
|
1115 |
"#sk-container-id-1 a.estimator_doc_link:hover {\n", |
|
|
1116 |
" /* unfitted */\n", |
|
|
1117 |
" background-color: var(--sklearn-color-unfitted-level-3);\n", |
|
|
1118 |
" color: var(--sklearn-color-background);\n", |
|
|
1119 |
" text-decoration: none;\n", |
|
|
1120 |
"}\n", |
|
|
1121 |
"\n", |
|
|
1122 |
"#sk-container-id-1 a.estimator_doc_link.fitted:hover {\n", |
|
|
1123 |
" /* fitted */\n", |
|
|
1124 |
" background-color: var(--sklearn-color-fitted-level-3);\n", |
|
|
1125 |
"}\n", |
|
|
1126 |
"</style><div id=\"sk-container-id-1\" class=\"sk-top-container\"><div class=\"sk-text-repr-fallback\"><pre>GridSearchCV(cv=5, estimator=DecisionTreeClassifier(), n_jobs=-1,\n", |
|
|
1127 |
" param_grid={'criterion': ['gini', 'entropy'],\n", |
|
|
1128 |
" 'max_depth': range(2, 32),\n", |
|
|
1129 |
" 'min_samples_leaf': range(1, 10),\n", |
|
|
1130 |
" 'min_samples_split': range(2, 10),\n", |
|
|
1131 |
" 'splitter': ['best', 'random']},\n", |
|
|
1132 |
" verbose=1)</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 sk-dashed-wrapped\"><div class=\"sk-label-container\"><div class=\"sk-label fitted sk-toggleable\"><input class=\"sk-toggleable__control sk-hidden--visually\" id=\"sk-estimator-id-1\" type=\"checkbox\" ><label for=\"sk-estimator-id-1\" class=\"sk-toggleable__label fitted sk-toggleable__label-arrow fitted\"> GridSearchCV<a class=\"sk-estimator-doc-link fitted\" rel=\"noreferrer\" target=\"_blank\" href=\"https://scikit-learn.org/1.4/modules/generated/sklearn.model_selection.GridSearchCV.html\">?<span>Documentation for GridSearchCV</span></a><span class=\"sk-estimator-doc-link fitted\">i<span>Fitted</span></span></label><div class=\"sk-toggleable__content fitted\"><pre>GridSearchCV(cv=5, estimator=DecisionTreeClassifier(), n_jobs=-1,\n", |
|
|
1133 |
" param_grid={'criterion': ['gini', 'entropy'],\n", |
|
|
1134 |
" 'max_depth': range(2, 32),\n", |
|
|
1135 |
" 'min_samples_leaf': range(1, 10),\n", |
|
|
1136 |
" 'min_samples_split': range(2, 10),\n", |
|
|
1137 |
" 'splitter': ['best', 'random']},\n", |
|
|
1138 |
" verbose=1)</pre></div> </div></div><div class=\"sk-parallel\"><div class=\"sk-parallel-item\"><div class=\"sk-item\"><div class=\"sk-label-container\"><div class=\"sk-label fitted sk-toggleable\"><input class=\"sk-toggleable__control sk-hidden--visually\" id=\"sk-estimator-id-2\" type=\"checkbox\" ><label for=\"sk-estimator-id-2\" class=\"sk-toggleable__label fitted sk-toggleable__label-arrow fitted\">estimator: DecisionTreeClassifier</label><div class=\"sk-toggleable__content fitted\"><pre>DecisionTreeClassifier()</pre></div> </div></div><div class=\"sk-serial\"><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\" ><label for=\"sk-estimator-id-3\" class=\"sk-toggleable__label fitted sk-toggleable__label-arrow fitted\"> DecisionTreeClassifier<a class=\"sk-estimator-doc-link fitted\" rel=\"noreferrer\" target=\"_blank\" href=\"https://scikit-learn.org/1.4/modules/generated/sklearn.tree.DecisionTreeClassifier.html\">?<span>Documentation for DecisionTreeClassifier</span></a></label><div class=\"sk-toggleable__content fitted\"><pre>DecisionTreeClassifier()</pre></div> </div></div></div></div></div></div></div></div></div>" |
|
|
1139 |
], |
|
|
1140 |
"text/plain": [ |
|
|
1141 |
"GridSearchCV(cv=5, estimator=DecisionTreeClassifier(), n_jobs=-1,\n", |
|
|
1142 |
" param_grid={'criterion': ['gini', 'entropy'],\n", |
|
|
1143 |
" 'max_depth': range(2, 32),\n", |
|
|
1144 |
" 'min_samples_leaf': range(1, 10),\n", |
|
|
1145 |
" 'min_samples_split': range(2, 10),\n", |
|
|
1146 |
" 'splitter': ['best', 'random']},\n", |
|
|
1147 |
" verbose=1)" |
|
|
1148 |
] |
|
|
1149 |
}, |
|
|
1150 |
"execution_count": 12, |
|
|
1151 |
"metadata": {}, |
|
|
1152 |
"output_type": "execute_result" |
|
|
1153 |
} |
|
|
1154 |
], |
|
|
1155 |
"source": [ |
|
|
1156 |
"from sklearn.tree import DecisionTreeClassifier\n", |
|
|
1157 |
"\n", |
|
|
1158 |
"dtc = DecisionTreeClassifier()\n", |
|
|
1159 |
"\n", |
|
|
1160 |
"parameters = {\n", |
|
|
1161 |
" 'criterion' : ['gini', 'entropy'],\n", |
|
|
1162 |
" 'max_depth' : range(2, 32, 1),\n", |
|
|
1163 |
" 'min_samples_leaf' : range(1, 10, 1),\n", |
|
|
1164 |
" 'min_samples_split' : range(2, 10, 1),\n", |
|
|
1165 |
" 'splitter' : ['best', 'random']\n", |
|
|
1166 |
"}\n", |
|
|
1167 |
"\n", |
|
|
1168 |
"grid_search_dt = GridSearchCV(dtc, parameters, cv = 5, n_jobs = -1, verbose = 1)\n", |
|
|
1169 |
"grid_search_dt.fit(A_training, B_training)" |
|
|
1170 |
] |
|
|
1171 |
}, |
|
|
1172 |
{ |
|
|
1173 |
"cell_type": "code", |
|
|
1174 |
"execution_count": 13, |
|
|
1175 |
"id": "362b8867-1ec8-4eba-84b0-c98486db2d2f", |
|
|
1176 |
"metadata": {}, |
|
|
1177 |
"outputs": [ |
|
|
1178 |
{ |
|
|
1179 |
"data": { |
|
|
1180 |
"text/html": [ |
|
|
1181 |
"<style>#sk-container-id-2 {\n", |
|
|
1182 |
" /* Definition of color scheme common for light and dark mode */\n", |
|
|
1183 |
" --sklearn-color-text: black;\n", |
|
|
1184 |
" --sklearn-color-line: gray;\n", |
|
|
1185 |
" /* Definition of color scheme for unfitted estimators */\n", |
|
|
1186 |
" --sklearn-color-unfitted-level-0: #fff5e6;\n", |
|
|
1187 |
" --sklearn-color-unfitted-level-1: #f6e4d2;\n", |
|
|
1188 |
" --sklearn-color-unfitted-level-2: #ffe0b3;\n", |
|
|
1189 |
" --sklearn-color-unfitted-level-3: chocolate;\n", |
|
|
1190 |
" /* Definition of color scheme for fitted estimators */\n", |
|
|
1191 |
" --sklearn-color-fitted-level-0: #f0f8ff;\n", |
|
|
1192 |
" --sklearn-color-fitted-level-1: #d4ebff;\n", |
|
|
1193 |
" --sklearn-color-fitted-level-2: #b3dbfd;\n", |
|
|
1194 |
" --sklearn-color-fitted-level-3: cornflowerblue;\n", |
|
|
1195 |
"\n", |
|
|
1196 |
" /* Specific color for light theme */\n", |
|
|
1197 |
" --sklearn-color-text-on-default-background: var(--sg-text-color, var(--theme-code-foreground, var(--jp-content-font-color1, black)));\n", |
|
|
1198 |
" --sklearn-color-background: var(--sg-background-color, var(--theme-background, var(--jp-layout-color0, white)));\n", |
|
|
1199 |
" --sklearn-color-border-box: var(--sg-text-color, var(--theme-code-foreground, var(--jp-content-font-color1, black)));\n", |
|
|
1200 |
" --sklearn-color-icon: #696969;\n", |
|
|
1201 |
"\n", |
|
|
1202 |
" @media (prefers-color-scheme: dark) {\n", |
|
|
1203 |
" /* Redefinition of color scheme for dark theme */\n", |
|
|
1204 |
" --sklearn-color-text-on-default-background: var(--sg-text-color, var(--theme-code-foreground, var(--jp-content-font-color1, white)));\n", |
|
|
1205 |
" --sklearn-color-background: var(--sg-background-color, var(--theme-background, var(--jp-layout-color0, #111)));\n", |
|
|
1206 |
" --sklearn-color-border-box: var(--sg-text-color, var(--theme-code-foreground, var(--jp-content-font-color1, white)));\n", |
|
|
1207 |
" --sklearn-color-icon: #878787;\n", |
|
|
1208 |
" }\n", |
|
|
1209 |
"}\n", |
|
|
1210 |
"\n", |
|
|
1211 |
"#sk-container-id-2 {\n", |
|
|
1212 |
" color: var(--sklearn-color-text);\n", |
|
|
1213 |
"}\n", |
|
|
1214 |
"\n", |
|
|
1215 |
"#sk-container-id-2 pre {\n", |
|
|
1216 |
" padding: 0;\n", |
|
|
1217 |
"}\n", |
|
|
1218 |
"\n", |
|
|
1219 |
"#sk-container-id-2 input.sk-hidden--visually {\n", |
|
|
1220 |
" border: 0;\n", |
|
|
1221 |
" clip: rect(1px 1px 1px 1px);\n", |
|
|
1222 |
" clip: rect(1px, 1px, 1px, 1px);\n", |
|
|
1223 |
" height: 1px;\n", |
|
|
1224 |
" margin: -1px;\n", |
|
|
1225 |
" overflow: hidden;\n", |
|
|
1226 |
" padding: 0;\n", |
|
|
1227 |
" position: absolute;\n", |
|
|
1228 |
" width: 1px;\n", |
|
|
1229 |
"}\n", |
|
|
1230 |
"\n", |
|
|
1231 |
"#sk-container-id-2 div.sk-dashed-wrapped {\n", |
|
|
1232 |
" border: 1px dashed var(--sklearn-color-line);\n", |
|
|
1233 |
" margin: 0 0.4em 0.5em 0.4em;\n", |
|
|
1234 |
" box-sizing: border-box;\n", |
|
|
1235 |
" padding-bottom: 0.4em;\n", |
|
|
1236 |
" background-color: var(--sklearn-color-background);\n", |
|
|
1237 |
"}\n", |
|
|
1238 |
"\n", |
|
|
1239 |
"#sk-container-id-2 div.sk-container {\n", |
|
|
1240 |
" /* jupyter's `normalize.less` sets `[hidden] { display: none; }`\n", |
|
|
1241 |
" but bootstrap.min.css set `[hidden] { display: none !important; }`\n", |
|
|
1242 |
" so we also need the `!important` here to be able to override the\n", |
|
|
1243 |
" default hidden behavior on the sphinx rendered scikit-learn.org.\n", |
|
|
1244 |
" See: https://github.com/scikit-learn/scikit-learn/issues/21755 */\n", |
|
|
1245 |
" display: inline-block !important;\n", |
|
|
1246 |
" position: relative;\n", |
|
|
1247 |
"}\n", |
|
|
1248 |
"\n", |
|
|
1249 |
"#sk-container-id-2 div.sk-text-repr-fallback {\n", |
|
|
1250 |
" display: none;\n", |
|
|
1251 |
"}\n", |
|
|
1252 |
"\n", |
|
|
1253 |
"div.sk-parallel-item,\n", |
|
|
1254 |
"div.sk-serial,\n", |
|
|
1255 |
"div.sk-item {\n", |
|
|
1256 |
" /* draw centered vertical line to link estimators */\n", |
|
|
1257 |
" background-image: linear-gradient(var(--sklearn-color-text-on-default-background), var(--sklearn-color-text-on-default-background));\n", |
|
|
1258 |
" background-size: 2px 100%;\n", |
|
|
1259 |
" background-repeat: no-repeat;\n", |
|
|
1260 |
" background-position: center center;\n", |
|
|
1261 |
"}\n", |
|
|
1262 |
"\n", |
|
|
1263 |
"/* Parallel-specific style estimator block */\n", |
|
|
1264 |
"\n", |
|
|
1265 |
"#sk-container-id-2 div.sk-parallel-item::after {\n", |
|
|
1266 |
" content: \"\";\n", |
|
|
1267 |
" width: 100%;\n", |
|
|
1268 |
" border-bottom: 2px solid var(--sklearn-color-text-on-default-background);\n", |
|
|
1269 |
" flex-grow: 1;\n", |
|
|
1270 |
"}\n", |
|
|
1271 |
"\n", |
|
|
1272 |
"#sk-container-id-2 div.sk-parallel {\n", |
|
|
1273 |
" display: flex;\n", |
|
|
1274 |
" align-items: stretch;\n", |
|
|
1275 |
" justify-content: center;\n", |
|
|
1276 |
" background-color: var(--sklearn-color-background);\n", |
|
|
1277 |
" position: relative;\n", |
|
|
1278 |
"}\n", |
|
|
1279 |
"\n", |
|
|
1280 |
"#sk-container-id-2 div.sk-parallel-item {\n", |
|
|
1281 |
" display: flex;\n", |
|
|
1282 |
" flex-direction: column;\n", |
|
|
1283 |
"}\n", |
|
|
1284 |
"\n", |
|
|
1285 |
"#sk-container-id-2 div.sk-parallel-item:first-child::after {\n", |
|
|
1286 |
" align-self: flex-end;\n", |
|
|
1287 |
" width: 50%;\n", |
|
|
1288 |
"}\n", |
|
|
1289 |
"\n", |
|
|
1290 |
"#sk-container-id-2 div.sk-parallel-item:last-child::after {\n", |
|
|
1291 |
" align-self: flex-start;\n", |
|
|
1292 |
" width: 50%;\n", |
|
|
1293 |
"}\n", |
|
|
1294 |
"\n", |
|
|
1295 |
"#sk-container-id-2 div.sk-parallel-item:only-child::after {\n", |
|
|
1296 |
" width: 0;\n", |
|
|
1297 |
"}\n", |
|
|
1298 |
"\n", |
|
|
1299 |
"/* Serial-specific style estimator block */\n", |
|
|
1300 |
"\n", |
|
|
1301 |
"#sk-container-id-2 div.sk-serial {\n", |
|
|
1302 |
" display: flex;\n", |
|
|
1303 |
" flex-direction: column;\n", |
|
|
1304 |
" align-items: center;\n", |
|
|
1305 |
" background-color: var(--sklearn-color-background);\n", |
|
|
1306 |
" padding-right: 1em;\n", |
|
|
1307 |
" padding-left: 1em;\n", |
|
|
1308 |
"}\n", |
|
|
1309 |
"\n", |
|
|
1310 |
"\n", |
|
|
1311 |
"/* Toggleable style: style used for estimator/Pipeline/ColumnTransformer box that is\n", |
|
|
1312 |
"clickable and can be expanded/collapsed.\n", |
|
|
1313 |
"- Pipeline and ColumnTransformer use this feature and define the default style\n", |
|
|
1314 |
"- Estimators will overwrite some part of the style using the `sk-estimator` class\n", |
|
|
1315 |
"*/\n", |
|
|
1316 |
"\n", |
|
|
1317 |
"/* Pipeline and ColumnTransformer style (default) */\n", |
|
|
1318 |
"\n", |
|
|
1319 |
"#sk-container-id-2 div.sk-toggleable {\n", |
|
|
1320 |
" /* Default theme specific background. It is overwritten whether we have a\n", |
|
|
1321 |
" specific estimator or a Pipeline/ColumnTransformer */\n", |
|
|
1322 |
" background-color: var(--sklearn-color-background);\n", |
|
|
1323 |
"}\n", |
|
|
1324 |
"\n", |
|
|
1325 |
"/* Toggleable label */\n", |
|
|
1326 |
"#sk-container-id-2 label.sk-toggleable__label {\n", |
|
|
1327 |
" cursor: pointer;\n", |
|
|
1328 |
" display: block;\n", |
|
|
1329 |
" width: 100%;\n", |
|
|
1330 |
" margin-bottom: 0;\n", |
|
|
1331 |
" padding: 0.5em;\n", |
|
|
1332 |
" box-sizing: border-box;\n", |
|
|
1333 |
" text-align: center;\n", |
|
|
1334 |
"}\n", |
|
|
1335 |
"\n", |
|
|
1336 |
"#sk-container-id-2 label.sk-toggleable__label-arrow:before {\n", |
|
|
1337 |
" /* Arrow on the left of the label */\n", |
|
|
1338 |
" content: \"▸\";\n", |
|
|
1339 |
" float: left;\n", |
|
|
1340 |
" margin-right: 0.25em;\n", |
|
|
1341 |
" color: var(--sklearn-color-icon);\n", |
|
|
1342 |
"}\n", |
|
|
1343 |
"\n", |
|
|
1344 |
"#sk-container-id-2 label.sk-toggleable__label-arrow:hover:before {\n", |
|
|
1345 |
" color: var(--sklearn-color-text);\n", |
|
|
1346 |
"}\n", |
|
|
1347 |
"\n", |
|
|
1348 |
"/* Toggleable content - dropdown */\n", |
|
|
1349 |
"\n", |
|
|
1350 |
"#sk-container-id-2 div.sk-toggleable__content {\n", |
|
|
1351 |
" max-height: 0;\n", |
|
|
1352 |
" max-width: 0;\n", |
|
|
1353 |
" overflow: hidden;\n", |
|
|
1354 |
" text-align: left;\n", |
|
|
1355 |
" /* unfitted */\n", |
|
|
1356 |
" background-color: var(--sklearn-color-unfitted-level-0);\n", |
|
|
1357 |
"}\n", |
|
|
1358 |
"\n", |
|
|
1359 |
"#sk-container-id-2 div.sk-toggleable__content.fitted {\n", |
|
|
1360 |
" /* fitted */\n", |
|
|
1361 |
" background-color: var(--sklearn-color-fitted-level-0);\n", |
|
|
1362 |
"}\n", |
|
|
1363 |
"\n", |
|
|
1364 |
"#sk-container-id-2 div.sk-toggleable__content pre {\n", |
|
|
1365 |
" margin: 0.2em;\n", |
|
|
1366 |
" border-radius: 0.25em;\n", |
|
|
1367 |
" color: var(--sklearn-color-text);\n", |
|
|
1368 |
" /* unfitted */\n", |
|
|
1369 |
" background-color: var(--sklearn-color-unfitted-level-0);\n", |
|
|
1370 |
"}\n", |
|
|
1371 |
"\n", |
|
|
1372 |
"#sk-container-id-2 div.sk-toggleable__content.fitted pre {\n", |
|
|
1373 |
" /* unfitted */\n", |
|
|
1374 |
" background-color: var(--sklearn-color-fitted-level-0);\n", |
|
|
1375 |
"}\n", |
|
|
1376 |
"\n", |
|
|
1377 |
"#sk-container-id-2 input.sk-toggleable__control:checked~div.sk-toggleable__content {\n", |
|
|
1378 |
" /* Expand drop-down */\n", |
|
|
1379 |
" max-height: 200px;\n", |
|
|
1380 |
" max-width: 100%;\n", |
|
|
1381 |
" overflow: auto;\n", |
|
|
1382 |
"}\n", |
|
|
1383 |
"\n", |
|
|
1384 |
"#sk-container-id-2 input.sk-toggleable__control:checked~label.sk-toggleable__label-arrow:before {\n", |
|
|
1385 |
" content: \"▾\";\n", |
|
|
1386 |
"}\n", |
|
|
1387 |
"\n", |
|
|
1388 |
"/* Pipeline/ColumnTransformer-specific style */\n", |
|
|
1389 |
"\n", |
|
|
1390 |
"#sk-container-id-2 div.sk-label input.sk-toggleable__control:checked~label.sk-toggleable__label {\n", |
|
|
1391 |
" color: var(--sklearn-color-text);\n", |
|
|
1392 |
" background-color: var(--sklearn-color-unfitted-level-2);\n", |
|
|
1393 |
"}\n", |
|
|
1394 |
"\n", |
|
|
1395 |
"#sk-container-id-2 div.sk-label.fitted input.sk-toggleable__control:checked~label.sk-toggleable__label {\n", |
|
|
1396 |
" background-color: var(--sklearn-color-fitted-level-2);\n", |
|
|
1397 |
"}\n", |
|
|
1398 |
"\n", |
|
|
1399 |
"/* Estimator-specific style */\n", |
|
|
1400 |
"\n", |
|
|
1401 |
"/* Colorize estimator box */\n", |
|
|
1402 |
"#sk-container-id-2 div.sk-estimator input.sk-toggleable__control:checked~label.sk-toggleable__label {\n", |
|
|
1403 |
" /* unfitted */\n", |
|
|
1404 |
" background-color: var(--sklearn-color-unfitted-level-2);\n", |
|
|
1405 |
"}\n", |
|
|
1406 |
"\n", |
|
|
1407 |
"#sk-container-id-2 div.sk-estimator.fitted input.sk-toggleable__control:checked~label.sk-toggleable__label {\n", |
|
|
1408 |
" /* fitted */\n", |
|
|
1409 |
" background-color: var(--sklearn-color-fitted-level-2);\n", |
|
|
1410 |
"}\n", |
|
|
1411 |
"\n", |
|
|
1412 |
"#sk-container-id-2 div.sk-label label.sk-toggleable__label,\n", |
|
|
1413 |
"#sk-container-id-2 div.sk-label label {\n", |
|
|
1414 |
" /* The background is the default theme color */\n", |
|
|
1415 |
" color: var(--sklearn-color-text-on-default-background);\n", |
|
|
1416 |
"}\n", |
|
|
1417 |
"\n", |
|
|
1418 |
"/* On hover, darken the color of the background */\n", |
|
|
1419 |
"#sk-container-id-2 div.sk-label:hover label.sk-toggleable__label {\n", |
|
|
1420 |
" color: var(--sklearn-color-text);\n", |
|
|
1421 |
" background-color: var(--sklearn-color-unfitted-level-2);\n", |
|
|
1422 |
"}\n", |
|
|
1423 |
"\n", |
|
|
1424 |
"/* Label box, darken color on hover, fitted */\n", |
|
|
1425 |
"#sk-container-id-2 div.sk-label.fitted:hover label.sk-toggleable__label.fitted {\n", |
|
|
1426 |
" color: var(--sklearn-color-text);\n", |
|
|
1427 |
" background-color: var(--sklearn-color-fitted-level-2);\n", |
|
|
1428 |
"}\n", |
|
|
1429 |
"\n", |
|
|
1430 |
"/* Estimator label */\n", |
|
|
1431 |
"\n", |
|
|
1432 |
"#sk-container-id-2 div.sk-label label {\n", |
|
|
1433 |
" font-family: monospace;\n", |
|
|
1434 |
" font-weight: bold;\n", |
|
|
1435 |
" display: inline-block;\n", |
|
|
1436 |
" line-height: 1.2em;\n", |
|
|
1437 |
"}\n", |
|
|
1438 |
"\n", |
|
|
1439 |
"#sk-container-id-2 div.sk-label-container {\n", |
|
|
1440 |
" text-align: center;\n", |
|
|
1441 |
"}\n", |
|
|
1442 |
"\n", |
|
|
1443 |
"/* Estimator-specific */\n", |
|
|
1444 |
"#sk-container-id-2 div.sk-estimator {\n", |
|
|
1445 |
" font-family: monospace;\n", |
|
|
1446 |
" border: 1px dotted var(--sklearn-color-border-box);\n", |
|
|
1447 |
" border-radius: 0.25em;\n", |
|
|
1448 |
" box-sizing: border-box;\n", |
|
|
1449 |
" margin-bottom: 0.5em;\n", |
|
|
1450 |
" /* unfitted */\n", |
|
|
1451 |
" background-color: var(--sklearn-color-unfitted-level-0);\n", |
|
|
1452 |
"}\n", |
|
|
1453 |
"\n", |
|
|
1454 |
"#sk-container-id-2 div.sk-estimator.fitted {\n", |
|
|
1455 |
" /* fitted */\n", |
|
|
1456 |
" background-color: var(--sklearn-color-fitted-level-0);\n", |
|
|
1457 |
"}\n", |
|
|
1458 |
"\n", |
|
|
1459 |
"/* on hover */\n", |
|
|
1460 |
"#sk-container-id-2 div.sk-estimator:hover {\n", |
|
|
1461 |
" /* unfitted */\n", |
|
|
1462 |
" background-color: var(--sklearn-color-unfitted-level-2);\n", |
|
|
1463 |
"}\n", |
|
|
1464 |
"\n", |
|
|
1465 |
"#sk-container-id-2 div.sk-estimator.fitted:hover {\n", |
|
|
1466 |
" /* fitted */\n", |
|
|
1467 |
" background-color: var(--sklearn-color-fitted-level-2);\n", |
|
|
1468 |
"}\n", |
|
|
1469 |
"\n", |
|
|
1470 |
"/* Specification for estimator info (e.g. \"i\" and \"?\") */\n", |
|
|
1471 |
"\n", |
|
|
1472 |
"/* Common style for \"i\" and \"?\" */\n", |
|
|
1473 |
"\n", |
|
|
1474 |
".sk-estimator-doc-link,\n", |
|
|
1475 |
"a:link.sk-estimator-doc-link,\n", |
|
|
1476 |
"a:visited.sk-estimator-doc-link {\n", |
|
|
1477 |
" float: right;\n", |
|
|
1478 |
" font-size: smaller;\n", |
|
|
1479 |
" line-height: 1em;\n", |
|
|
1480 |
" font-family: monospace;\n", |
|
|
1481 |
" background-color: var(--sklearn-color-background);\n", |
|
|
1482 |
" border-radius: 1em;\n", |
|
|
1483 |
" height: 1em;\n", |
|
|
1484 |
" width: 1em;\n", |
|
|
1485 |
" text-decoration: none !important;\n", |
|
|
1486 |
" margin-left: 1ex;\n", |
|
|
1487 |
" /* unfitted */\n", |
|
|
1488 |
" border: var(--sklearn-color-unfitted-level-1) 1pt solid;\n", |
|
|
1489 |
" color: var(--sklearn-color-unfitted-level-1);\n", |
|
|
1490 |
"}\n", |
|
|
1491 |
"\n", |
|
|
1492 |
".sk-estimator-doc-link.fitted,\n", |
|
|
1493 |
"a:link.sk-estimator-doc-link.fitted,\n", |
|
|
1494 |
"a:visited.sk-estimator-doc-link.fitted {\n", |
|
|
1495 |
" /* fitted */\n", |
|
|
1496 |
" border: var(--sklearn-color-fitted-level-1) 1pt solid;\n", |
|
|
1497 |
" color: var(--sklearn-color-fitted-level-1);\n", |
|
|
1498 |
"}\n", |
|
|
1499 |
"\n", |
|
|
1500 |
"/* On hover */\n", |
|
|
1501 |
"div.sk-estimator:hover .sk-estimator-doc-link:hover,\n", |
|
|
1502 |
".sk-estimator-doc-link:hover,\n", |
|
|
1503 |
"div.sk-label-container:hover .sk-estimator-doc-link:hover,\n", |
|
|
1504 |
".sk-estimator-doc-link:hover {\n", |
|
|
1505 |
" /* unfitted */\n", |
|
|
1506 |
" background-color: var(--sklearn-color-unfitted-level-3);\n", |
|
|
1507 |
" color: var(--sklearn-color-background);\n", |
|
|
1508 |
" text-decoration: none;\n", |
|
|
1509 |
"}\n", |
|
|
1510 |
"\n", |
|
|
1511 |
"div.sk-estimator.fitted:hover .sk-estimator-doc-link.fitted:hover,\n", |
|
|
1512 |
".sk-estimator-doc-link.fitted:hover,\n", |
|
|
1513 |
"div.sk-label-container:hover .sk-estimator-doc-link.fitted:hover,\n", |
|
|
1514 |
".sk-estimator-doc-link.fitted:hover {\n", |
|
|
1515 |
" /* fitted */\n", |
|
|
1516 |
" background-color: var(--sklearn-color-fitted-level-3);\n", |
|
|
1517 |
" color: var(--sklearn-color-background);\n", |
|
|
1518 |
" text-decoration: none;\n", |
|
|
1519 |
"}\n", |
|
|
1520 |
"\n", |
|
|
1521 |
"/* Span, style for the box shown on hovering the info icon */\n", |
|
|
1522 |
".sk-estimator-doc-link span {\n", |
|
|
1523 |
" display: none;\n", |
|
|
1524 |
" z-index: 9999;\n", |
|
|
1525 |
" position: relative;\n", |
|
|
1526 |
" font-weight: normal;\n", |
|
|
1527 |
" right: .2ex;\n", |
|
|
1528 |
" padding: .5ex;\n", |
|
|
1529 |
" margin: .5ex;\n", |
|
|
1530 |
" width: min-content;\n", |
|
|
1531 |
" min-width: 20ex;\n", |
|
|
1532 |
" max-width: 50ex;\n", |
|
|
1533 |
" color: var(--sklearn-color-text);\n", |
|
|
1534 |
" box-shadow: 2pt 2pt 4pt #999;\n", |
|
|
1535 |
" /* unfitted */\n", |
|
|
1536 |
" background: var(--sklearn-color-unfitted-level-0);\n", |
|
|
1537 |
" border: .5pt solid var(--sklearn-color-unfitted-level-3);\n", |
|
|
1538 |
"}\n", |
|
|
1539 |
"\n", |
|
|
1540 |
".sk-estimator-doc-link.fitted span {\n", |
|
|
1541 |
" /* fitted */\n", |
|
|
1542 |
" background: var(--sklearn-color-fitted-level-0);\n", |
|
|
1543 |
" border: var(--sklearn-color-fitted-level-3);\n", |
|
|
1544 |
"}\n", |
|
|
1545 |
"\n", |
|
|
1546 |
".sk-estimator-doc-link:hover span {\n", |
|
|
1547 |
" display: block;\n", |
|
|
1548 |
"}\n", |
|
|
1549 |
"\n", |
|
|
1550 |
"/* \"?\"-specific style due to the `<a>` HTML tag */\n", |
|
|
1551 |
"\n", |
|
|
1552 |
"#sk-container-id-2 a.estimator_doc_link {\n", |
|
|
1553 |
" float: right;\n", |
|
|
1554 |
" font-size: 1rem;\n", |
|
|
1555 |
" line-height: 1em;\n", |
|
|
1556 |
" font-family: monospace;\n", |
|
|
1557 |
" background-color: var(--sklearn-color-background);\n", |
|
|
1558 |
" border-radius: 1rem;\n", |
|
|
1559 |
" height: 1rem;\n", |
|
|
1560 |
" width: 1rem;\n", |
|
|
1561 |
" text-decoration: none;\n", |
|
|
1562 |
" /* unfitted */\n", |
|
|
1563 |
" color: var(--sklearn-color-unfitted-level-1);\n", |
|
|
1564 |
" border: var(--sklearn-color-unfitted-level-1) 1pt solid;\n", |
|
|
1565 |
"}\n", |
|
|
1566 |
"\n", |
|
|
1567 |
"#sk-container-id-2 a.estimator_doc_link.fitted {\n", |
|
|
1568 |
" /* fitted */\n", |
|
|
1569 |
" border: var(--sklearn-color-fitted-level-1) 1pt solid;\n", |
|
|
1570 |
" color: var(--sklearn-color-fitted-level-1);\n", |
|
|
1571 |
"}\n", |
|
|
1572 |
"\n", |
|
|
1573 |
"/* On hover */\n", |
|
|
1574 |
"#sk-container-id-2 a.estimator_doc_link:hover {\n", |
|
|
1575 |
" /* unfitted */\n", |
|
|
1576 |
" background-color: var(--sklearn-color-unfitted-level-3);\n", |
|
|
1577 |
" color: var(--sklearn-color-background);\n", |
|
|
1578 |
" text-decoration: none;\n", |
|
|
1579 |
"}\n", |
|
|
1580 |
"\n", |
|
|
1581 |
"#sk-container-id-2 a.estimator_doc_link.fitted:hover {\n", |
|
|
1582 |
" /* fitted */\n", |
|
|
1583 |
" background-color: var(--sklearn-color-fitted-level-3);\n", |
|
|
1584 |
"}\n", |
|
|
1585 |
"</style><div id=\"sk-container-id-2\" class=\"sk-top-container\"><div class=\"sk-text-repr-fallback\"><pre>DecisionTreeClassifier(criterion='entropy', max_depth=19, min_samples_leaf=4,\n", |
|
|
1586 |
" min_samples_split=6, splitter='random')</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 fitted\"> DecisionTreeClassifier<a class=\"sk-estimator-doc-link fitted\" rel=\"noreferrer\" target=\"_blank\" href=\"https://scikit-learn.org/1.4/modules/generated/sklearn.tree.DecisionTreeClassifier.html\">?<span>Documentation for DecisionTreeClassifier</span></a><span class=\"sk-estimator-doc-link fitted\">i<span>Fitted</span></span></label><div class=\"sk-toggleable__content fitted\"><pre>DecisionTreeClassifier(criterion='entropy', max_depth=19, min_samples_leaf=4,\n", |
|
|
1587 |
" min_samples_split=6, splitter='random')</pre></div> </div></div></div></div>" |
|
|
1588 |
], |
|
|
1589 |
"text/plain": [ |
|
|
1590 |
"DecisionTreeClassifier(criterion='entropy', max_depth=19, min_samples_leaf=4,\n", |
|
|
1591 |
" min_samples_split=6, splitter='random')" |
|
|
1592 |
] |
|
|
1593 |
}, |
|
|
1594 |
"execution_count": 13, |
|
|
1595 |
"metadata": {}, |
|
|
1596 |
"output_type": "execute_result" |
|
|
1597 |
} |
|
|
1598 |
], |
|
|
1599 |
"source": [ |
|
|
1600 |
"\n", |
|
|
1601 |
"dtc = DecisionTreeClassifier(criterion= 'entropy', max_depth= 19, min_samples_leaf= 4, min_samples_split= 6, splitter= 'random')\n", |
|
|
1602 |
"dtc.fit(A_training, B_training)" |
|
|
1603 |
] |
|
|
1604 |
}, |
|
|
1605 |
{ |
|
|
1606 |
"cell_type": "code", |
|
|
1607 |
"execution_count": 14, |
|
|
1608 |
"id": "2ac9e062-42ce-4baa-81f6-b004efa79279", |
|
|
1609 |
"metadata": {}, |
|
|
1610 |
"outputs": [ |
|
|
1611 |
{ |
|
|
1612 |
"name": "stdout", |
|
|
1613 |
"output_type": "stream", |
|
|
1614 |
"text": [ |
|
|
1615 |
"0.9132231404958677\n", |
|
|
1616 |
"0.6885245901639344\n" |
|
|
1617 |
] |
|
|
1618 |
} |
|
|
1619 |
], |
|
|
1620 |
"source": [ |
|
|
1621 |
"B_pred = dtc.predict(A_testing)\n", |
|
|
1622 |
"# accuracy score\n", |
|
|
1623 |
"\n", |
|
|
1624 |
"print(accuracy_score(B_training, dtc.predict(A_training)))\n", |
|
|
1625 |
"\n", |
|
|
1626 |
"dtc_acc = accuracy_score(B_testing, dtc.predict(A_testing))\n", |
|
|
1627 |
"print(dtc_acc)" |
|
|
1628 |
] |
|
|
1629 |
}, |
|
|
1630 |
{ |
|
|
1631 |
"cell_type": "code", |
|
|
1632 |
"execution_count": 15, |
|
|
1633 |
"id": "23941f55-8363-4bdd-a552-1bbb83f1c206", |
|
|
1634 |
"metadata": {}, |
|
|
1635 |
"outputs": [ |
|
|
1636 |
{ |
|
|
1637 |
"name": "stdout", |
|
|
1638 |
"output_type": "stream", |
|
|
1639 |
"text": [ |
|
|
1640 |
" precision recall f1-score support\n", |
|
|
1641 |
"\n", |
|
|
1642 |
" 0 0.67 0.64 0.65 28\n", |
|
|
1643 |
" 1 0.71 0.73 0.72 33\n", |
|
|
1644 |
"\n", |
|
|
1645 |
" accuracy 0.69 61\n", |
|
|
1646 |
" macro avg 0.69 0.69 0.69 61\n", |
|
|
1647 |
"weighted avg 0.69 0.69 0.69 61\n", |
|
|
1648 |
"\n" |
|
|
1649 |
] |
|
|
1650 |
} |
|
|
1651 |
], |
|
|
1652 |
"source": [ |
|
|
1653 |
"# classification report\n", |
|
|
1654 |
"\n", |
|
|
1655 |
"print(classification_report(B_testing, B_pred))" |
|
|
1656 |
] |
|
|
1657 |
}, |
|
|
1658 |
{ |
|
|
1659 |
"cell_type": "code", |
|
|
1660 |
"execution_count": 16, |
|
|
1661 |
"id": "029bfdba-3d0e-4d3a-9ce1-06fe8de61f82", |
|
|
1662 |
"metadata": {}, |
|
|
1663 |
"outputs": [ |
|
|
1664 |
{ |
|
|
1665 |
"data": { |
|
|
1666 |
"text/html": [ |
|
|
1667 |
"<div>\n", |
|
|
1668 |
"<style scoped>\n", |
|
|
1669 |
" .dataframe tbody tr th:only-of-type {\n", |
|
|
1670 |
" vertical-align: middle;\n", |
|
|
1671 |
" }\n", |
|
|
1672 |
"\n", |
|
|
1673 |
" .dataframe tbody tr th {\n", |
|
|
1674 |
" vertical-align: top;\n", |
|
|
1675 |
" }\n", |
|
|
1676 |
"\n", |
|
|
1677 |
" .dataframe thead th {\n", |
|
|
1678 |
" text-align: right;\n", |
|
|
1679 |
" }\n", |
|
|
1680 |
"</style>\n", |
|
|
1681 |
"<table border=\"1\" class=\"dataframe\">\n", |
|
|
1682 |
" <thead>\n", |
|
|
1683 |
" <tr style=\"text-align: right;\">\n", |
|
|
1684 |
" <th></th>\n", |
|
|
1685 |
" <th>Model</th>\n", |
|
|
1686 |
" <th>Score</th>\n", |
|
|
1687 |
" </tr>\n", |
|
|
1688 |
" </thead>\n", |
|
|
1689 |
" <tbody>\n", |
|
|
1690 |
" <tr>\n", |
|
|
1691 |
" <th>0</th>\n", |
|
|
1692 |
" <td>Logistic Regression</td>\n", |
|
|
1693 |
" <td>81.97</td>\n", |
|
|
1694 |
" </tr>\n", |
|
|
1695 |
" <tr>\n", |
|
|
1696 |
" <th>3</th>\n", |
|
|
1697 |
" <td>Decision Tree Classifier</td>\n", |
|
|
1698 |
" <td>68.85</td>\n", |
|
|
1699 |
" </tr>\n", |
|
|
1700 |
" <tr>\n", |
|
|
1701 |
" <th>1</th>\n", |
|
|
1702 |
" <td>KNN</td>\n", |
|
|
1703 |
" <td>62.30</td>\n", |
|
|
1704 |
" </tr>\n", |
|
|
1705 |
" <tr>\n", |
|
|
1706 |
" <th>2</th>\n", |
|
|
1707 |
" <td>SVM</td>\n", |
|
|
1708 |
" <td>54.10</td>\n", |
|
|
1709 |
" </tr>\n", |
|
|
1710 |
" </tbody>\n", |
|
|
1711 |
"</table>\n", |
|
|
1712 |
"</div>" |
|
|
1713 |
], |
|
|
1714 |
"text/plain": [ |
|
|
1715 |
" Model Score\n", |
|
|
1716 |
"0 Logistic Regression 81.97\n", |
|
|
1717 |
"3 Decision Tree Classifier 68.85\n", |
|
|
1718 |
"1 KNN 62.30\n", |
|
|
1719 |
"2 SVM 54.10" |
|
|
1720 |
] |
|
|
1721 |
}, |
|
|
1722 |
"execution_count": 16, |
|
|
1723 |
"metadata": {}, |
|
|
1724 |
"output_type": "execute_result" |
|
|
1725 |
} |
|
|
1726 |
], |
|
|
1727 |
"source": [ |
|
|
1728 |
"models = pd.DataFrame({\n", |
|
|
1729 |
" 'Model': ['Logistic Regression', 'KNN', 'SVM', 'Decision Tree Classifier'],\n", |
|
|
1730 |
" 'Score': [100*round(log_reg_acc,4), 100*round(knn_acc,4), 100*round(svc_acc,4), 100*round(dtc_acc,4)]\n", |
|
|
1731 |
"})\n", |
|
|
1732 |
"models.sort_values(by = 'Score', ascending = False)" |
|
|
1733 |
] |
|
|
1734 |
}, |
|
|
1735 |
{ |
|
|
1736 |
"cell_type": "code", |
|
|
1737 |
"execution_count": 17, |
|
|
1738 |
"id": "12de1159", |
|
|
1739 |
"metadata": {}, |
|
|
1740 |
"outputs": [ |
|
|
1741 |
{ |
|
|
1742 |
"name": "stdout", |
|
|
1743 |
"output_type": "stream", |
|
|
1744 |
"text": [ |
|
|
1745 |
" age sex cp trestbps chol fbs restecg thalach exang oldpeak \\\n", |
|
|
1746 |
"165 67 1 0 160 286 0 0 108 1 1.5 \n", |
|
|
1747 |
"166 67 1 0 120 229 0 0 129 1 2.6 \n", |
|
|
1748 |
"167 62 0 0 140 268 0 0 160 0 3.6 \n", |
|
|
1749 |
"168 63 1 0 130 254 0 0 147 0 1.4 \n", |
|
|
1750 |
"169 53 1 0 140 203 1 0 155 1 3.1 \n", |
|
|
1751 |
".. ... ... .. ... ... ... ... ... ... ... \n", |
|
|
1752 |
"298 57 0 0 140 241 0 1 123 1 0.2 \n", |
|
|
1753 |
"299 45 1 3 110 264 0 1 132 0 1.2 \n", |
|
|
1754 |
"300 68 1 0 144 193 1 1 141 0 3.4 \n", |
|
|
1755 |
"301 57 1 0 130 131 0 1 115 1 1.2 \n", |
|
|
1756 |
"302 57 0 1 130 236 0 0 174 0 0.0 \n", |
|
|
1757 |
"\n", |
|
|
1758 |
" slope ca thal target \n", |
|
|
1759 |
"165 1 3 2 0 \n", |
|
|
1760 |
"166 1 2 3 0 \n", |
|
|
1761 |
"167 0 2 2 0 \n", |
|
|
1762 |
"168 1 1 3 0 \n", |
|
|
1763 |
"169 0 0 3 0 \n", |
|
|
1764 |
".. ... .. ... ... \n", |
|
|
1765 |
"298 1 0 3 0 \n", |
|
|
1766 |
"299 1 0 3 0 \n", |
|
|
1767 |
"300 1 2 3 0 \n", |
|
|
1768 |
"301 1 1 3 0 \n", |
|
|
1769 |
"302 1 1 2 0 \n", |
|
|
1770 |
"\n", |
|
|
1771 |
"[138 rows x 14 columns]\n" |
|
|
1772 |
] |
|
|
1773 |
} |
|
|
1774 |
], |
|
|
1775 |
"source": [ |
|
|
1776 |
"filtered_df = df[df['target'] == 0]\n", |
|
|
1777 |
"C = pd.DataFrame(filtered_df) \n", |
|
|
1778 |
"print(C)\n" |
|
|
1779 |
] |
|
|
1780 |
}, |
|
|
1781 |
{ |
|
|
1782 |
"cell_type": "code", |
|
|
1783 |
"execution_count": null, |
|
|
1784 |
"id": "9ea84040-eb10-42f2-97c7-f91b52129aef", |
|
|
1785 |
"metadata": {}, |
|
|
1786 |
"outputs": [ |
|
|
1787 |
{ |
|
|
1788 |
"name": "stdout", |
|
|
1789 |
"output_type": "stream", |
|
|
1790 |
"text": [ |
|
|
1791 |
"[1]\n" |
|
|
1792 |
] |
|
|
1793 |
}, |
|
|
1794 |
{ |
|
|
1795 |
"name": "stderr", |
|
|
1796 |
"output_type": "stream", |
|
|
1797 |
"text": [ |
|
|
1798 |
"c:\\Users\\Pranshu Saini\\AppData\\Local\\Programs\\Python\\Python312\\Lib\\site-packages\\sklearn\\base.py:493: UserWarning: X does not have valid feature names, but LogisticRegression was fitted with feature names\n", |
|
|
1799 |
" warnings.warn(\n" |
|
|
1800 |
] |
|
|
1801 |
} |
|
|
1802 |
], |
|
|
1803 |
"source": [ |
|
|
1804 |
"import numpy as np\n", |
|
|
1805 |
"\n", |
|
|
1806 |
"a = [63, 1, 3, 145, 233, 1, 0, 150, 0, 2.3, 0, 0, 1]\n", |
|
|
1807 |
"b=[67 , 1, 0, 160, 286, 0, 0, 108, 1, 1.5, 1, 3, 2 ]\n", |
|
|
1808 |
"a_reshaped = np.array().reshape(1, -1)\n", |
|
|
1809 |
"\n", |
|
|
1810 |
"B = log_reg.predict(a_reshaped)\n", |
|
|
1811 |
"print(B)\n" |
|
|
1812 |
] |
|
|
1813 |
}, |
|
|
1814 |
{ |
|
|
1815 |
"cell_type": "code", |
|
|
1816 |
"execution_count": null, |
|
|
1817 |
"id": "e66f5d96-79a7-4ac9-a01b-e753181af587", |
|
|
1818 |
"metadata": {}, |
|
|
1819 |
"outputs": [], |
|
|
1820 |
"source": [] |
|
|
1821 |
}, |
|
|
1822 |
{ |
|
|
1823 |
"cell_type": "code", |
|
|
1824 |
"execution_count": 20, |
|
|
1825 |
"id": "7552b5a0-d407-4bf9-98e0-56b8bd7c3245", |
|
|
1826 |
"metadata": {}, |
|
|
1827 |
"outputs": [], |
|
|
1828 |
"source": [ |
|
|
1829 |
"import pickle\n", |
|
|
1830 |
"filename = r'C:\\Users\\Pranshu Saini\\Desktop\\disease-prediction-main\\docpat\\model\\heart_disease_model.pkl'\n", |
|
|
1831 |
"pickle.dump(log_reg, open(filename, 'wb'))" |
|
|
1832 |
] |
|
|
1833 |
}, |
|
|
1834 |
{ |
|
|
1835 |
"cell_type": "code", |
|
|
1836 |
"execution_count": null, |
|
|
1837 |
"id": "4f01bd6a-95cc-4383-a17c-0e0ae3ff2e69", |
|
|
1838 |
"metadata": {}, |
|
|
1839 |
"outputs": [], |
|
|
1840 |
"source": [ |
|
|
1841 |
"'''import pickle\n", |
|
|
1842 |
"def load_model(path):\n", |
|
|
1843 |
" with open(path, 'rb') as file:\n", |
|
|
1844 |
" model = pickle.load(file)\n", |
|
|
1845 |
"heart_model = load_model(r'C:\\Users\\DELL\\Desktop\\app\\heart_disease_model.pkl')\n", |
|
|
1846 |
"def predict(inputs):\n", |
|
|
1847 |
" return heart_model.predict(inputs)'''" |
|
|
1848 |
] |
|
|
1849 |
}, |
|
|
1850 |
{ |
|
|
1851 |
"cell_type": "code", |
|
|
1852 |
"execution_count": null, |
|
|
1853 |
"id": "3765e3cf-d221-4413-a91e-9b7d4d49bd3c", |
|
|
1854 |
"metadata": {}, |
|
|
1855 |
"outputs": [], |
|
|
1856 |
"source": [] |
|
|
1857 |
}, |
|
|
1858 |
{ |
|
|
1859 |
"cell_type": "code", |
|
|
1860 |
"execution_count": null, |
|
|
1861 |
"id": "a8fc26d0", |
|
|
1862 |
"metadata": {}, |
|
|
1863 |
"outputs": [], |
|
|
1864 |
"source": [] |
|
|
1865 |
}, |
|
|
1866 |
{ |
|
|
1867 |
"cell_type": "code", |
|
|
1868 |
"execution_count": null, |
|
|
1869 |
"id": "66257935", |
|
|
1870 |
"metadata": {}, |
|
|
1871 |
"outputs": [], |
|
|
1872 |
"source": [] |
|
|
1873 |
} |
|
|
1874 |
], |
|
|
1875 |
"metadata": { |
|
|
1876 |
"kernelspec": { |
|
|
1877 |
"display_name": "Python 3", |
|
|
1878 |
"language": "python", |
|
|
1879 |
"name": "python3" |
|
|
1880 |
}, |
|
|
1881 |
"language_info": { |
|
|
1882 |
"codemirror_mode": { |
|
|
1883 |
"name": "ipython", |
|
|
1884 |
"version": 3 |
|
|
1885 |
}, |
|
|
1886 |
"file_extension": ".py", |
|
|
1887 |
"mimetype": "text/x-python", |
|
|
1888 |
"name": "python", |
|
|
1889 |
"nbconvert_exporter": "python", |
|
|
1890 |
"pygments_lexer": "ipython3", |
|
|
1891 |
"version": "3.12.3" |
|
|
1892 |
} |
|
|
1893 |
}, |
|
|
1894 |
"nbformat": 4, |
|
|
1895 |
"nbformat_minor": 5 |
|
|
1896 |
} |