aaladnan commited on
Commit
fdd914b
·
verified ·
1 Parent(s): 548ad89

Upload Blood-Pressure-Model/Blood-Pressure-Model.ipynb with huggingface_hub

Browse files
Blood-Pressure-Model/Blood-Pressure-Model.ipynb ADDED
@@ -0,0 +1,870 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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": 4,
20
+ "metadata": {
21
+ "id": "hrzjDZhCykSv"
22
+ },
23
+ "outputs": [],
24
+ "source": [
25
+ "import pandas as pd\n",
26
+ "import numpy as np\n",
27
+ "from sklearn.model_selection import train_test_split\n",
28
+ "from sklearn.neighbors import KNeighborsClassifier\n",
29
+ "from sklearn.tree import DecisionTreeClassifier\n",
30
+ "from sklearn.metrics import accuracy_score\n",
31
+ "import joblib"
32
+ ]
33
+ },
34
+ {
35
+ "cell_type": "code",
36
+ "source": [
37
+ "df = pd.read_csv('/content/data.csv')\n",
38
+ "df.head()"
39
+ ],
40
+ "metadata": {
41
+ "colab": {
42
+ "base_uri": "https://localhost:8080/",
43
+ "height": 226
44
+ },
45
+ "id": "siRGOC_PzCmJ",
46
+ "outputId": "717f6dc4-a613-4c62-ffea-631977c1ede7"
47
+ },
48
+ "execution_count": 5,
49
+ "outputs": [
50
+ {
51
+ "output_type": "execute_result",
52
+ "data": {
53
+ "text/plain": [
54
+ " Patient_Number Blood_Pressure_Abnormality Level_of_Hemoglobin \\\n",
55
+ "0 1 1 11.28 \n",
56
+ "1 2 0 9.75 \n",
57
+ "2 3 1 10.79 \n",
58
+ "3 4 0 11.00 \n",
59
+ "4 5 1 14.17 \n",
60
+ "\n",
61
+ " Genetic_Pedigree_Coefficient Age BMI Sex Pregnancy Smoking \\\n",
62
+ "0 0.90 34 23 1 1.0 0 \n",
63
+ "1 0.23 54 33 1 NaN 0 \n",
64
+ "2 0.91 70 49 0 NaN 0 \n",
65
+ "3 0.43 71 50 0 NaN 0 \n",
66
+ "4 0.83 52 19 0 NaN 0 \n",
67
+ "\n",
68
+ " Physical_activity salt_content_in_the_diet alcohol_consumption_per_day \\\n",
69
+ "0 45961 48071 NaN \n",
70
+ "1 26106 25333 205.0 \n",
71
+ "2 9995 29465 67.0 \n",
72
+ "3 10635 7439 242.0 \n",
73
+ "4 15619 49644 397.0 \n",
74
+ "\n",
75
+ " Level_of_Stress Chronic_kidney_disease Adrenal_and_thyroid_disorders \n",
76
+ "0 2 1 1 \n",
77
+ "1 3 0 0 \n",
78
+ "2 2 1 0 \n",
79
+ "3 1 1 0 \n",
80
+ "4 2 0 0 "
81
+ ],
82
+ "text/html": [
83
+ "\n",
84
+ " <div id=\"df-a6acadf9-54f4-4026-8fdc-1e5b8c3080d6\" class=\"colab-df-container\">\n",
85
+ " <div>\n",
86
+ "<style scoped>\n",
87
+ " .dataframe tbody tr th:only-of-type {\n",
88
+ " vertical-align: middle;\n",
89
+ " }\n",
90
+ "\n",
91
+ " .dataframe tbody tr th {\n",
92
+ " vertical-align: top;\n",
93
+ " }\n",
94
+ "\n",
95
+ " .dataframe thead th {\n",
96
+ " text-align: right;\n",
97
+ " }\n",
98
+ "</style>\n",
99
+ "<table border=\"1\" class=\"dataframe\">\n",
100
+ " <thead>\n",
101
+ " <tr style=\"text-align: right;\">\n",
102
+ " <th></th>\n",
103
+ " <th>Patient_Number</th>\n",
104
+ " <th>Blood_Pressure_Abnormality</th>\n",
105
+ " <th>Level_of_Hemoglobin</th>\n",
106
+ " <th>Genetic_Pedigree_Coefficient</th>\n",
107
+ " <th>Age</th>\n",
108
+ " <th>BMI</th>\n",
109
+ " <th>Sex</th>\n",
110
+ " <th>Pregnancy</th>\n",
111
+ " <th>Smoking</th>\n",
112
+ " <th>Physical_activity</th>\n",
113
+ " <th>salt_content_in_the_diet</th>\n",
114
+ " <th>alcohol_consumption_per_day</th>\n",
115
+ " <th>Level_of_Stress</th>\n",
116
+ " <th>Chronic_kidney_disease</th>\n",
117
+ " <th>Adrenal_and_thyroid_disorders</th>\n",
118
+ " </tr>\n",
119
+ " </thead>\n",
120
+ " <tbody>\n",
121
+ " <tr>\n",
122
+ " <th>0</th>\n",
123
+ " <td>1</td>\n",
124
+ " <td>1</td>\n",
125
+ " <td>11.28</td>\n",
126
+ " <td>0.90</td>\n",
127
+ " <td>34</td>\n",
128
+ " <td>23</td>\n",
129
+ " <td>1</td>\n",
130
+ " <td>1.0</td>\n",
131
+ " <td>0</td>\n",
132
+ " <td>45961</td>\n",
133
+ " <td>48071</td>\n",
134
+ " <td>NaN</td>\n",
135
+ " <td>2</td>\n",
136
+ " <td>1</td>\n",
137
+ " <td>1</td>\n",
138
+ " </tr>\n",
139
+ " <tr>\n",
140
+ " <th>1</th>\n",
141
+ " <td>2</td>\n",
142
+ " <td>0</td>\n",
143
+ " <td>9.75</td>\n",
144
+ " <td>0.23</td>\n",
145
+ " <td>54</td>\n",
146
+ " <td>33</td>\n",
147
+ " <td>1</td>\n",
148
+ " <td>NaN</td>\n",
149
+ " <td>0</td>\n",
150
+ " <td>26106</td>\n",
151
+ " <td>25333</td>\n",
152
+ " <td>205.0</td>\n",
153
+ " <td>3</td>\n",
154
+ " <td>0</td>\n",
155
+ " <td>0</td>\n",
156
+ " </tr>\n",
157
+ " <tr>\n",
158
+ " <th>2</th>\n",
159
+ " <td>3</td>\n",
160
+ " <td>1</td>\n",
161
+ " <td>10.79</td>\n",
162
+ " <td>0.91</td>\n",
163
+ " <td>70</td>\n",
164
+ " <td>49</td>\n",
165
+ " <td>0</td>\n",
166
+ " <td>NaN</td>\n",
167
+ " <td>0</td>\n",
168
+ " <td>9995</td>\n",
169
+ " <td>29465</td>\n",
170
+ " <td>67.0</td>\n",
171
+ " <td>2</td>\n",
172
+ " <td>1</td>\n",
173
+ " <td>0</td>\n",
174
+ " </tr>\n",
175
+ " <tr>\n",
176
+ " <th>3</th>\n",
177
+ " <td>4</td>\n",
178
+ " <td>0</td>\n",
179
+ " <td>11.00</td>\n",
180
+ " <td>0.43</td>\n",
181
+ " <td>71</td>\n",
182
+ " <td>50</td>\n",
183
+ " <td>0</td>\n",
184
+ " <td>NaN</td>\n",
185
+ " <td>0</td>\n",
186
+ " <td>10635</td>\n",
187
+ " <td>7439</td>\n",
188
+ " <td>242.0</td>\n",
189
+ " <td>1</td>\n",
190
+ " <td>1</td>\n",
191
+ " <td>0</td>\n",
192
+ " </tr>\n",
193
+ " <tr>\n",
194
+ " <th>4</th>\n",
195
+ " <td>5</td>\n",
196
+ " <td>1</td>\n",
197
+ " <td>14.17</td>\n",
198
+ " <td>0.83</td>\n",
199
+ " <td>52</td>\n",
200
+ " <td>19</td>\n",
201
+ " <td>0</td>\n",
202
+ " <td>NaN</td>\n",
203
+ " <td>0</td>\n",
204
+ " <td>15619</td>\n",
205
+ " <td>49644</td>\n",
206
+ " <td>397.0</td>\n",
207
+ " <td>2</td>\n",
208
+ " <td>0</td>\n",
209
+ " <td>0</td>\n",
210
+ " </tr>\n",
211
+ " </tbody>\n",
212
+ "</table>\n",
213
+ "</div>\n",
214
+ " <div class=\"colab-df-buttons\">\n",
215
+ "\n",
216
+ " <div class=\"colab-df-container\">\n",
217
+ " <button class=\"colab-df-convert\" onclick=\"convertToInteractive('df-a6acadf9-54f4-4026-8fdc-1e5b8c3080d6')\"\n",
218
+ " title=\"Convert this dataframe to an interactive table.\"\n",
219
+ " style=\"display:none;\">\n",
220
+ "\n",
221
+ " <svg xmlns=\"http://www.w3.org/2000/svg\" height=\"24px\" viewBox=\"0 -960 960 960\">\n",
222
+ " <path d=\"M120-120v-720h720v720H120Zm60-500h600v-160H180v160Zm220 220h160v-160H400v160Zm0 220h160v-160H400v160ZM180-400h160v-160H180v160Zm440 0h160v-160H620v160ZM180-180h160v-160H180v160Zm440 0h160v-160H620v160Z\"/>\n",
223
+ " </svg>\n",
224
+ " </button>\n",
225
+ "\n",
226
+ " <style>\n",
227
+ " .colab-df-container {\n",
228
+ " display:flex;\n",
229
+ " gap: 12px;\n",
230
+ " }\n",
231
+ "\n",
232
+ " .colab-df-convert {\n",
233
+ " background-color: #E8F0FE;\n",
234
+ " border: none;\n",
235
+ " border-radius: 50%;\n",
236
+ " cursor: pointer;\n",
237
+ " display: none;\n",
238
+ " fill: #1967D2;\n",
239
+ " height: 32px;\n",
240
+ " padding: 0 0 0 0;\n",
241
+ " width: 32px;\n",
242
+ " }\n",
243
+ "\n",
244
+ " .colab-df-convert:hover {\n",
245
+ " background-color: #E2EBFA;\n",
246
+ " box-shadow: 0px 1px 2px rgba(60, 64, 67, 0.3), 0px 1px 3px 1px rgba(60, 64, 67, 0.15);\n",
247
+ " fill: #174EA6;\n",
248
+ " }\n",
249
+ "\n",
250
+ " .colab-df-buttons div {\n",
251
+ " margin-bottom: 4px;\n",
252
+ " }\n",
253
+ "\n",
254
+ " [theme=dark] .colab-df-convert {\n",
255
+ " background-color: #3B4455;\n",
256
+ " fill: #D2E3FC;\n",
257
+ " }\n",
258
+ "\n",
259
+ " [theme=dark] .colab-df-convert:hover {\n",
260
+ " background-color: #434B5C;\n",
261
+ " box-shadow: 0px 1px 3px 1px rgba(0, 0, 0, 0.15);\n",
262
+ " filter: drop-shadow(0px 1px 2px rgba(0, 0, 0, 0.3));\n",
263
+ " fill: #FFFFFF;\n",
264
+ " }\n",
265
+ " </style>\n",
266
+ "\n",
267
+ " <script>\n",
268
+ " const buttonEl =\n",
269
+ " document.querySelector('#df-a6acadf9-54f4-4026-8fdc-1e5b8c3080d6 button.colab-df-convert');\n",
270
+ " buttonEl.style.display =\n",
271
+ " google.colab.kernel.accessAllowed ? 'block' : 'none';\n",
272
+ "\n",
273
+ " async function convertToInteractive(key) {\n",
274
+ " const element = document.querySelector('#df-a6acadf9-54f4-4026-8fdc-1e5b8c3080d6');\n",
275
+ " const dataTable =\n",
276
+ " await google.colab.kernel.invokeFunction('convertToInteractive',\n",
277
+ " [key], {});\n",
278
+ " if (!dataTable) return;\n",
279
+ "\n",
280
+ " const docLinkHtml = 'Like what you see? Visit the ' +\n",
281
+ " '<a target=\"_blank\" href=https://colab.research.google.com/notebooks/data_table.ipynb>data table notebook</a>'\n",
282
+ " + ' to learn more about interactive tables.';\n",
283
+ " element.innerHTML = '';\n",
284
+ " dataTable['output_type'] = 'display_data';\n",
285
+ " await google.colab.output.renderOutput(dataTable, element);\n",
286
+ " const docLink = document.createElement('div');\n",
287
+ " docLink.innerHTML = docLinkHtml;\n",
288
+ " element.appendChild(docLink);\n",
289
+ " }\n",
290
+ " </script>\n",
291
+ " </div>\n",
292
+ "\n",
293
+ "\n",
294
+ "<div id=\"df-ea9d1e6e-a766-48f3-9c85-119dbca73b67\">\n",
295
+ " <button class=\"colab-df-quickchart\" onclick=\"quickchart('df-ea9d1e6e-a766-48f3-9c85-119dbca73b67')\"\n",
296
+ " title=\"Suggest charts\"\n",
297
+ " style=\"display:none;\">\n",
298
+ "\n",
299
+ "<svg xmlns=\"http://www.w3.org/2000/svg\" height=\"24px\"viewBox=\"0 0 24 24\"\n",
300
+ " width=\"24px\">\n",
301
+ " <g>\n",
302
+ " <path d=\"M19 3H5c-1.1 0-2 .9-2 2v14c0 1.1.9 2 2 2h14c1.1 0 2-.9 2-2V5c0-1.1-.9-2-2-2zM9 17H7v-7h2v7zm4 0h-2V7h2v10zm4 0h-2v-4h2v4z\"/>\n",
303
+ " </g>\n",
304
+ "</svg>\n",
305
+ " </button>\n",
306
+ "\n",
307
+ "<style>\n",
308
+ " .colab-df-quickchart {\n",
309
+ " --bg-color: #E8F0FE;\n",
310
+ " --fill-color: #1967D2;\n",
311
+ " --hover-bg-color: #E2EBFA;\n",
312
+ " --hover-fill-color: #174EA6;\n",
313
+ " --disabled-fill-color: #AAA;\n",
314
+ " --disabled-bg-color: #DDD;\n",
315
+ " }\n",
316
+ "\n",
317
+ " [theme=dark] .colab-df-quickchart {\n",
318
+ " --bg-color: #3B4455;\n",
319
+ " --fill-color: #D2E3FC;\n",
320
+ " --hover-bg-color: #434B5C;\n",
321
+ " --hover-fill-color: #FFFFFF;\n",
322
+ " --disabled-bg-color: #3B4455;\n",
323
+ " --disabled-fill-color: #666;\n",
324
+ " }\n",
325
+ "\n",
326
+ " .colab-df-quickchart {\n",
327
+ " background-color: var(--bg-color);\n",
328
+ " border: none;\n",
329
+ " border-radius: 50%;\n",
330
+ " cursor: pointer;\n",
331
+ " display: none;\n",
332
+ " fill: var(--fill-color);\n",
333
+ " height: 32px;\n",
334
+ " padding: 0;\n",
335
+ " width: 32px;\n",
336
+ " }\n",
337
+ "\n",
338
+ " .colab-df-quickchart:hover {\n",
339
+ " background-color: var(--hover-bg-color);\n",
340
+ " box-shadow: 0 1px 2px rgba(60, 64, 67, 0.3), 0 1px 3px 1px rgba(60, 64, 67, 0.15);\n",
341
+ " fill: var(--button-hover-fill-color);\n",
342
+ " }\n",
343
+ "\n",
344
+ " .colab-df-quickchart-complete:disabled,\n",
345
+ " .colab-df-quickchart-complete:disabled:hover {\n",
346
+ " background-color: var(--disabled-bg-color);\n",
347
+ " fill: var(--disabled-fill-color);\n",
348
+ " box-shadow: none;\n",
349
+ " }\n",
350
+ "\n",
351
+ " .colab-df-spinner {\n",
352
+ " border: 2px solid var(--fill-color);\n",
353
+ " border-color: transparent;\n",
354
+ " border-bottom-color: var(--fill-color);\n",
355
+ " animation:\n",
356
+ " spin 1s steps(1) infinite;\n",
357
+ " }\n",
358
+ "\n",
359
+ " @keyframes spin {\n",
360
+ " 0% {\n",
361
+ " border-color: transparent;\n",
362
+ " border-bottom-color: var(--fill-color);\n",
363
+ " border-left-color: var(--fill-color);\n",
364
+ " }\n",
365
+ " 20% {\n",
366
+ " border-color: transparent;\n",
367
+ " border-left-color: var(--fill-color);\n",
368
+ " border-top-color: var(--fill-color);\n",
369
+ " }\n",
370
+ " 30% {\n",
371
+ " border-color: transparent;\n",
372
+ " border-left-color: var(--fill-color);\n",
373
+ " border-top-color: var(--fill-color);\n",
374
+ " border-right-color: var(--fill-color);\n",
375
+ " }\n",
376
+ " 40% {\n",
377
+ " border-color: transparent;\n",
378
+ " border-right-color: var(--fill-color);\n",
379
+ " border-top-color: var(--fill-color);\n",
380
+ " }\n",
381
+ " 60% {\n",
382
+ " border-color: transparent;\n",
383
+ " border-right-color: var(--fill-color);\n",
384
+ " }\n",
385
+ " 80% {\n",
386
+ " border-color: transparent;\n",
387
+ " border-right-color: var(--fill-color);\n",
388
+ " border-bottom-color: var(--fill-color);\n",
389
+ " }\n",
390
+ " 90% {\n",
391
+ " border-color: transparent;\n",
392
+ " border-bottom-color: var(--fill-color);\n",
393
+ " }\n",
394
+ " }\n",
395
+ "</style>\n",
396
+ "\n",
397
+ " <script>\n",
398
+ " async function quickchart(key) {\n",
399
+ " const quickchartButtonEl =\n",
400
+ " document.querySelector('#' + key + ' button');\n",
401
+ " quickchartButtonEl.disabled = true; // To prevent multiple clicks.\n",
402
+ " quickchartButtonEl.classList.add('colab-df-spinner');\n",
403
+ " try {\n",
404
+ " const charts = await google.colab.kernel.invokeFunction(\n",
405
+ " 'suggestCharts', [key], {});\n",
406
+ " } catch (error) {\n",
407
+ " console.error('Error during call to suggestCharts:', error);\n",
408
+ " }\n",
409
+ " quickchartButtonEl.classList.remove('colab-df-spinner');\n",
410
+ " quickchartButtonEl.classList.add('colab-df-quickchart-complete');\n",
411
+ " }\n",
412
+ " (() => {\n",
413
+ " let quickchartButtonEl =\n",
414
+ " document.querySelector('#df-ea9d1e6e-a766-48f3-9c85-119dbca73b67 button');\n",
415
+ " quickchartButtonEl.style.display =\n",
416
+ " google.colab.kernel.accessAllowed ? 'block' : 'none';\n",
417
+ " })();\n",
418
+ " </script>\n",
419
+ "</div>\n",
420
+ "\n",
421
+ " </div>\n",
422
+ " </div>\n"
423
+ ],
424
+ "application/vnd.google.colaboratory.intrinsic+json": {
425
+ "type": "dataframe",
426
+ "variable_name": "df",
427
+ "summary": "{\n \"name\": \"df\",\n \"rows\": 2000,\n \"fields\": [\n {\n \"column\": \"Patient_Number\",\n \"properties\": {\n \"dtype\": \"number\",\n \"std\": 577,\n \"min\": 1,\n \"max\": 2000,\n \"num_unique_values\": 2000,\n \"samples\": [\n 1861,\n 354,\n 1334\n ],\n \"semantic_type\": \"\",\n \"description\": \"\"\n }\n },\n {\n \"column\": \"Blood_Pressure_Abnormality\",\n \"properties\": {\n \"dtype\": \"number\",\n \"std\": 0,\n \"min\": 0,\n \"max\": 1,\n \"num_unique_values\": 2,\n \"samples\": [\n 0,\n 1\n ],\n \"semantic_type\": \"\",\n \"description\": \"\"\n }\n },\n {\n \"column\": \"Level_of_Hemoglobin\",\n \"properties\": {\n \"dtype\": \"number\",\n \"std\": 2.1867006376306533,\n \"min\": 8.1,\n \"max\": 17.56,\n \"num_unique_values\": 757,\n \"samples\": [\n 9.2,\n 13.78\n ],\n \"semantic_type\": \"\",\n \"description\": \"\"\n }\n },\n {\n \"column\": \"Genetic_Pedigree_Coefficient\",\n \"properties\": {\n \"dtype\": \"number\",\n \"std\": 0.2917358818334813,\n \"min\": 0.0,\n \"max\": 1.0,\n \"num_unique_values\": 101,\n \"samples\": [\n 0.72,\n 0.12\n ],\n \"semantic_type\": \"\",\n \"description\": \"\"\n }\n },\n {\n \"column\": \"Age\",\n \"properties\": {\n \"dtype\": \"number\",\n \"std\": 17,\n \"min\": 18,\n \"max\": 75,\n \"num_unique_values\": 58,\n \"samples\": [\n 34,\n 23\n ],\n \"semantic_type\": \"\",\n \"description\": \"\"\n }\n },\n {\n \"column\": \"BMI\",\n \"properties\": {\n \"dtype\": \"number\",\n \"std\": 11,\n \"min\": 10,\n \"max\": 50,\n \"num_unique_values\": 41,\n \"samples\": [\n 18,\n 27\n ],\n \"semantic_type\": \"\",\n \"description\": \"\"\n }\n },\n {\n \"column\": \"Sex\",\n \"properties\": {\n \"dtype\": \"number\",\n \"std\": 0,\n \"min\": 0,\n \"max\": 1,\n \"num_unique_values\": 2,\n \"samples\": [\n 0,\n 1\n ],\n \"semantic_type\": \"\",\n \"description\": \"\"\n }\n },\n {\n \"column\": \"Pregnancy\",\n \"properties\": {\n \"dtype\": \"number\",\n \"std\": 0.4980801631506569,\n \"min\": 0.0,\n \"max\": 1.0,\n \"num_unique_values\": 2,\n \"samples\": [\n 0.0,\n 1.0\n ],\n \"semantic_type\": \"\",\n \"description\": \"\"\n }\n },\n {\n \"column\": \"Smoking\",\n \"properties\": {\n \"dtype\": \"number\",\n \"std\": 0,\n \"min\": 0,\n \"max\": 1,\n \"num_unique_values\": 2,\n \"samples\": [\n 1,\n 0\n ],\n \"semantic_type\": \"\",\n \"description\": \"\"\n }\n },\n {\n \"column\": \"Physical_activity\",\n \"properties\": {\n \"dtype\": \"number\",\n \"std\": 14015,\n \"min\": 628,\n \"max\": 49980,\n \"num_unique_values\": 1951,\n \"samples\": [\n 21467,\n 8470\n ],\n \"semantic_type\": \"\",\n \"description\": \"\"\n }\n },\n {\n \"column\": \"salt_content_in_the_diet\",\n \"properties\": {\n \"dtype\": \"number\",\n \"std\": 14211,\n \"min\": 22,\n \"max\": 49976,\n \"num_unique_values\": 1945,\n \"samples\": [\n 27777,\n 1674\n ],\n \"semantic_type\": \"\",\n \"description\": \"\"\n }\n },\n {\n \"column\": \"alcohol_consumption_per_day\",\n \"properties\": {\n \"dtype\": \"number\",\n \"std\": 143.65188442842302,\n \"min\": 0.0,\n \"max\": 499.0,\n \"num_unique_values\": 488,\n \"samples\": [\n 309.0,\n 467.0\n ],\n \"semantic_type\": \"\",\n \"description\": \"\"\n }\n },\n {\n \"column\": \"Level_of_Stress\",\n \"properties\": {\n \"dtype\": \"number\",\n \"std\": 0,\n \"min\": 1,\n \"max\": 3,\n \"num_unique_values\": 3,\n \"samples\": [\n 2,\n 3\n ],\n \"semantic_type\": \"\",\n \"description\": \"\"\n }\n },\n {\n \"column\": \"Chronic_kidney_disease\",\n \"properties\": {\n \"dtype\": \"number\",\n \"std\": 0,\n \"min\": 0,\n \"max\": 1,\n \"num_unique_values\": 2,\n \"samples\": [\n 0,\n 1\n ],\n \"semantic_type\": \"\",\n \"description\": \"\"\n }\n },\n {\n \"column\": \"Adrenal_and_thyroid_disorders\",\n \"properties\": {\n \"dtype\": \"number\",\n \"std\": 0,\n \"min\": 0,\n \"max\": 1,\n \"num_unique_values\": 2,\n \"samples\": [\n 0,\n 1\n ],\n \"semantic_type\": \"\",\n \"description\": \"\"\n }\n }\n ]\n}"
428
+ }
429
+ },
430
+ "metadata": {},
431
+ "execution_count": 5
432
+ }
433
+ ]
434
+ },
435
+ {
436
+ "cell_type": "code",
437
+ "source": [
438
+ "df.isnull().sum()"
439
+ ],
440
+ "metadata": {
441
+ "colab": {
442
+ "base_uri": "https://localhost:8080/",
443
+ "height": 554
444
+ },
445
+ "id": "SwpsDsCwzh2q",
446
+ "outputId": "fcb0a13e-35b5-4457-d58c-f0860fa90bfa"
447
+ },
448
+ "execution_count": 6,
449
+ "outputs": [
450
+ {
451
+ "output_type": "execute_result",
452
+ "data": {
453
+ "text/plain": [
454
+ "Patient_Number 0\n",
455
+ "Blood_Pressure_Abnormality 0\n",
456
+ "Level_of_Hemoglobin 0\n",
457
+ "Genetic_Pedigree_Coefficient 92\n",
458
+ "Age 0\n",
459
+ "BMI 0\n",
460
+ "Sex 0\n",
461
+ "Pregnancy 1558\n",
462
+ "Smoking 0\n",
463
+ "Physical_activity 0\n",
464
+ "salt_content_in_the_diet 0\n",
465
+ "alcohol_consumption_per_day 242\n",
466
+ "Level_of_Stress 0\n",
467
+ "Chronic_kidney_disease 0\n",
468
+ "Adrenal_and_thyroid_disorders 0\n",
469
+ "dtype: int64"
470
+ ],
471
+ "text/html": [
472
+ "<div>\n",
473
+ "<style scoped>\n",
474
+ " .dataframe tbody tr th:only-of-type {\n",
475
+ " vertical-align: middle;\n",
476
+ " }\n",
477
+ "\n",
478
+ " .dataframe tbody tr th {\n",
479
+ " vertical-align: top;\n",
480
+ " }\n",
481
+ "\n",
482
+ " .dataframe thead th {\n",
483
+ " text-align: right;\n",
484
+ " }\n",
485
+ "</style>\n",
486
+ "<table border=\"1\" class=\"dataframe\">\n",
487
+ " <thead>\n",
488
+ " <tr style=\"text-align: right;\">\n",
489
+ " <th></th>\n",
490
+ " <th>0</th>\n",
491
+ " </tr>\n",
492
+ " </thead>\n",
493
+ " <tbody>\n",
494
+ " <tr>\n",
495
+ " <th>Patient_Number</th>\n",
496
+ " <td>0</td>\n",
497
+ " </tr>\n",
498
+ " <tr>\n",
499
+ " <th>Blood_Pressure_Abnormality</th>\n",
500
+ " <td>0</td>\n",
501
+ " </tr>\n",
502
+ " <tr>\n",
503
+ " <th>Level_of_Hemoglobin</th>\n",
504
+ " <td>0</td>\n",
505
+ " </tr>\n",
506
+ " <tr>\n",
507
+ " <th>Genetic_Pedigree_Coefficient</th>\n",
508
+ " <td>92</td>\n",
509
+ " </tr>\n",
510
+ " <tr>\n",
511
+ " <th>Age</th>\n",
512
+ " <td>0</td>\n",
513
+ " </tr>\n",
514
+ " <tr>\n",
515
+ " <th>BMI</th>\n",
516
+ " <td>0</td>\n",
517
+ " </tr>\n",
518
+ " <tr>\n",
519
+ " <th>Sex</th>\n",
520
+ " <td>0</td>\n",
521
+ " </tr>\n",
522
+ " <tr>\n",
523
+ " <th>Pregnancy</th>\n",
524
+ " <td>1558</td>\n",
525
+ " </tr>\n",
526
+ " <tr>\n",
527
+ " <th>Smoking</th>\n",
528
+ " <td>0</td>\n",
529
+ " </tr>\n",
530
+ " <tr>\n",
531
+ " <th>Physical_activity</th>\n",
532
+ " <td>0</td>\n",
533
+ " </tr>\n",
534
+ " <tr>\n",
535
+ " <th>salt_content_in_the_diet</th>\n",
536
+ " <td>0</td>\n",
537
+ " </tr>\n",
538
+ " <tr>\n",
539
+ " <th>alcohol_consumption_per_day</th>\n",
540
+ " <td>242</td>\n",
541
+ " </tr>\n",
542
+ " <tr>\n",
543
+ " <th>Level_of_Stress</th>\n",
544
+ " <td>0</td>\n",
545
+ " </tr>\n",
546
+ " <tr>\n",
547
+ " <th>Chronic_kidney_disease</th>\n",
548
+ " <td>0</td>\n",
549
+ " </tr>\n",
550
+ " <tr>\n",
551
+ " <th>Adrenal_and_thyroid_disorders</th>\n",
552
+ " <td>0</td>\n",
553
+ " </tr>\n",
554
+ " </tbody>\n",
555
+ "</table>\n",
556
+ "</div><br><label><b>dtype:</b> int64</label>"
557
+ ]
558
+ },
559
+ "metadata": {},
560
+ "execution_count": 6
561
+ }
562
+ ]
563
+ },
564
+ {
565
+ "cell_type": "code",
566
+ "source": [
567
+ "df.fillna(df['Genetic_Pedigree_Coefficient'].mode()[0], inplace=True)\n",
568
+ "df.fillna(df['Pregnancy'].mode()[0], inplace=True)\n",
569
+ "df.fillna(df['alcohol_consumption_per_day'].median(), inplace=True)"
570
+ ],
571
+ "metadata": {
572
+ "id": "GMjkUTVVz-qu"
573
+ },
574
+ "execution_count": 7,
575
+ "outputs": []
576
+ },
577
+ {
578
+ "cell_type": "code",
579
+ "source": [
580
+ "df.drop(['Patient_Number','Adrenal_and_thyroid_disorders'], axis=1, inplace=True)"
581
+ ],
582
+ "metadata": {
583
+ "id": "f718ZzvP1cEa"
584
+ },
585
+ "execution_count": 8,
586
+ "outputs": []
587
+ },
588
+ {
589
+ "cell_type": "code",
590
+ "source": [
591
+ "df.info()"
592
+ ],
593
+ "metadata": {
594
+ "colab": {
595
+ "base_uri": "https://localhost:8080/"
596
+ },
597
+ "id": "9A2zk7wi040E",
598
+ "outputId": "89deac92-cebe-423e-8d57-46e3b14a616b"
599
+ },
600
+ "execution_count": 9,
601
+ "outputs": [
602
+ {
603
+ "output_type": "stream",
604
+ "name": "stdout",
605
+ "text": [
606
+ "<class 'pandas.core.frame.DataFrame'>\n",
607
+ "RangeIndex: 2000 entries, 0 to 1999\n",
608
+ "Data columns (total 13 columns):\n",
609
+ " # Column Non-Null Count Dtype \n",
610
+ "--- ------ -------------- ----- \n",
611
+ " 0 Blood_Pressure_Abnormality 2000 non-null int64 \n",
612
+ " 1 Level_of_Hemoglobin 2000 non-null float64\n",
613
+ " 2 Genetic_Pedigree_Coefficient 2000 non-null float64\n",
614
+ " 3 Age 2000 non-null int64 \n",
615
+ " 4 BMI 2000 non-null int64 \n",
616
+ " 5 Sex 2000 non-null int64 \n",
617
+ " 6 Pregnancy 2000 non-null float64\n",
618
+ " 7 Smoking 2000 non-null int64 \n",
619
+ " 8 Physical_activity 2000 non-null int64 \n",
620
+ " 9 salt_content_in_the_diet 2000 non-null int64 \n",
621
+ " 10 alcohol_consumption_per_day 2000 non-null float64\n",
622
+ " 11 Level_of_Stress 2000 non-null int64 \n",
623
+ " 12 Chronic_kidney_disease 2000 non-null int64 \n",
624
+ "dtypes: float64(4), int64(9)\n",
625
+ "memory usage: 203.3 KB\n"
626
+ ]
627
+ }
628
+ ]
629
+ },
630
+ {
631
+ "cell_type": "code",
632
+ "source": [
633
+ "X = df.drop('Blood_Pressure_Abnormality', axis=1)\n",
634
+ "y= df['Blood_Pressure_Abnormality']"
635
+ ],
636
+ "metadata": {
637
+ "id": "HW3rI9Jk1rsZ"
638
+ },
639
+ "execution_count": 10,
640
+ "outputs": []
641
+ },
642
+ {
643
+ "cell_type": "code",
644
+ "source": [
645
+ "X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=42, shuffle=True)"
646
+ ],
647
+ "metadata": {
648
+ "id": "zCLNqLbg2cz7"
649
+ },
650
+ "execution_count": 11,
651
+ "outputs": []
652
+ },
653
+ {
654
+ "cell_type": "code",
655
+ "source": [
656
+ "model_knn = KNeighborsClassifier(n_neighbors=5)\n",
657
+ "model_knn.fit(X_train, y_train)\n",
658
+ "y_knn_pred = model_knn.predict(X_test)\n",
659
+ "accuracy_knn = accuracy_score(y_test, y_knn_pred)\n",
660
+ "print(f\"KNN Accuracy: {accuracy_knn:.2f}\")"
661
+ ],
662
+ "metadata": {
663
+ "colab": {
664
+ "base_uri": "https://localhost:8080/"
665
+ },
666
+ "id": "2KlAwxHe2i7v",
667
+ "outputId": "10cab152-d656-4d93-e0c8-7f67c242a13c"
668
+ },
669
+ "execution_count": 12,
670
+ "outputs": [
671
+ {
672
+ "output_type": "stream",
673
+ "name": "stdout",
674
+ "text": [
675
+ "KNN Accuracy: 0.52\n"
676
+ ]
677
+ }
678
+ ]
679
+ },
680
+ {
681
+ "cell_type": "code",
682
+ "source": [
683
+ "model_dt=DecisionTreeClassifier(random_state=42)\n",
684
+ "model_dt.fit(X_train, y_train)\n",
685
+ "y_dt_pred = model_dt.predict(X_test)\n",
686
+ "accuracy_dt = accuracy_score(y_test, y_dt_pred)\n",
687
+ "print(f\"Decision Tree Accuracy: {accuracy_dt:.2f}\")"
688
+ ],
689
+ "metadata": {
690
+ "colab": {
691
+ "base_uri": "https://localhost:8080/"
692
+ },
693
+ "id": "L6f3-RKW29Fc",
694
+ "outputId": "4f71f2c9-1e12-4511-dec4-3262223e4dee"
695
+ },
696
+ "execution_count": 13,
697
+ "outputs": [
698
+ {
699
+ "output_type": "stream",
700
+ "name": "stdout",
701
+ "text": [
702
+ "Decision Tree Accuracy: 0.82\n"
703
+ ]
704
+ }
705
+ ]
706
+ },
707
+ {
708
+ "cell_type": "code",
709
+ "source": [
710
+ "joblib.dump(model_knn, 'model_knn.pkl')\n",
711
+ "joblib.dump(model_dt, 'model_dt.pkl')"
712
+ ],
713
+ "metadata": {
714
+ "colab": {
715
+ "base_uri": "https://localhost:8080/"
716
+ },
717
+ "id": "GB3vleCu3HwI",
718
+ "outputId": "985ba36a-afae-4d37-b404-72854358aaec"
719
+ },
720
+ "execution_count": 14,
721
+ "outputs": [
722
+ {
723
+ "output_type": "execute_result",
724
+ "data": {
725
+ "text/plain": [
726
+ "['model_dt.pkl']"
727
+ ]
728
+ },
729
+ "metadata": {},
730
+ "execution_count": 14
731
+ }
732
+ ]
733
+ },
734
+ {
735
+ "cell_type": "code",
736
+ "source": [
737
+ "loaded_knn = joblib.load('model_knn.pkl')\n",
738
+ "loaded_dt = joblib.load('model_dt.pkl')"
739
+ ],
740
+ "metadata": {
741
+ "id": "k0MoDhbE4WXG"
742
+ },
743
+ "execution_count": 15,
744
+ "outputs": []
745
+ },
746
+ {
747
+ "cell_type": "code",
748
+ "source": [
749
+ "df.info()"
750
+ ],
751
+ "metadata": {
752
+ "colab": {
753
+ "base_uri": "https://localhost:8080/"
754
+ },
755
+ "id": "qjJ5unz850gH",
756
+ "outputId": "88af5db0-f828-4245-8197-a9774761c1e9"
757
+ },
758
+ "execution_count": 16,
759
+ "outputs": [
760
+ {
761
+ "output_type": "stream",
762
+ "name": "stdout",
763
+ "text": [
764
+ "<class 'pandas.core.frame.DataFrame'>\n",
765
+ "RangeIndex: 2000 entries, 0 to 1999\n",
766
+ "Data columns (total 13 columns):\n",
767
+ " # Column Non-Null Count Dtype \n",
768
+ "--- ------ -------------- ----- \n",
769
+ " 0 Blood_Pressure_Abnormality 2000 non-null int64 \n",
770
+ " 1 Level_of_Hemoglobin 2000 non-null float64\n",
771
+ " 2 Genetic_Pedigree_Coefficient 2000 non-null float64\n",
772
+ " 3 Age 2000 non-null int64 \n",
773
+ " 4 BMI 2000 non-null int64 \n",
774
+ " 5 Sex 2000 non-null int64 \n",
775
+ " 6 Pregnancy 2000 non-null float64\n",
776
+ " 7 Smoking 2000 non-null int64 \n",
777
+ " 8 Physical_activity 2000 non-null int64 \n",
778
+ " 9 salt_content_in_the_diet 2000 non-null int64 \n",
779
+ " 10 alcohol_consumption_per_day 2000 non-null float64\n",
780
+ " 11 Level_of_Stress 2000 non-null int64 \n",
781
+ " 12 Chronic_kidney_disease 2000 non-null int64 \n",
782
+ "dtypes: float64(4), int64(9)\n",
783
+ "memory usage: 203.3 KB\n"
784
+ ]
785
+ }
786
+ ]
787
+ },
788
+ {
789
+ "cell_type": "code",
790
+ "source": [
791
+ "data_test= pd.DataFrame({\n",
792
+ " 'Level_of_Hemoglobin': np.random.uniform(12.0, 16.0, 400), # بين 12 و 16 g/dL\n",
793
+ " 'Genetic_Pedigree_Coefficient': np.random.uniform(0.1, 1.0, 400), # 0.1 إلى 1\n",
794
+ " 'Age': np.random.randint(18, 80, 400), # العمر بين 18 و 80 سنة\n",
795
+ " 'BMI': np.random.randint(18, 35, 400), # بين 18 و 35\n",
796
+ " 'Sex': np.random.randint(0, 2, 400), # 0 أو 1\n",
797
+ " 'Pregnancy': np.random.uniform(0, 1, 400), # بين 0 و 1\n",
798
+ " 'Smoking': np.random.randint(0, 2, 400), # 0 أو 1\n",
799
+ " 'Physical_activity': np.random.randint(0, 2, 400), # 0 أو 1\n",
800
+ " 'salt_content_in_the_diet': np.random.randint(1, 10, 400), # بين 1 و 10\n",
801
+ " 'alcohol_consumption_per_day': np.random.uniform(0, 400), # 0 كوب\n",
802
+ " 'Level_of_Stress': np.random.randint(0, 5, 400), # بين 0 و 4\n",
803
+ " 'Chronic_kidney_disease': np.random.randint(0, 2, 400), # 0 أو 1\n",
804
+ "})\n",
805
+ "\n",
806
+ "y_loaded_pred_k = loaded_knn.predict(data_test)\n",
807
+ "y_loaded_pred_d = loaded_dt.predict(data_test)"
808
+ ],
809
+ "metadata": {
810
+ "id": "we-HUFaH4cez"
811
+ },
812
+ "execution_count": 17,
813
+ "outputs": []
814
+ },
815
+ {
816
+ "cell_type": "code",
817
+ "source": [
818
+ "print(\"Predictions from KNN model:\", y_loaded_pred_k[:10]) # عرض أول 10 قيم من التنبؤات\n",
819
+ "print(\"Predictions from Decision Tree model:\", y_loaded_pred_d[:10])"
820
+ ],
821
+ "metadata": {
822
+ "colab": {
823
+ "base_uri": "https://localhost:8080/"
824
+ },
825
+ "id": "sjSzwAEQ6nfQ",
826
+ "outputId": "0f43af23-8cb0-4079-9fb5-7c4314a015ba"
827
+ },
828
+ "execution_count": 18,
829
+ "outputs": [
830
+ {
831
+ "output_type": "stream",
832
+ "name": "stdout",
833
+ "text": [
834
+ "Predictions from KNN model: [0 0 0 0 0 0 0 0 0 0]\n",
835
+ "Predictions from Decision Tree model: [1 1 1 1 1 0 0 0 0 1]\n"
836
+ ]
837
+ }
838
+ ]
839
+ },
840
+ {
841
+ "cell_type": "code",
842
+ "source": [
843
+ "# حساب الدقة\n",
844
+ "accuracy_k = accuracy_score(y_test, y_loaded_pred_k)\n",
845
+ "accuracy_d = accuracy_score(y_test, y_loaded_pred_d)\n",
846
+ "\n",
847
+ "print(\"Accuracy of KNN model:\", accuracy_k)\n",
848
+ "print(\"Accuracy of Decision Tree model:\", accuracy_d)"
849
+ ],
850
+ "metadata": {
851
+ "colab": {
852
+ "base_uri": "https://localhost:8080/"
853
+ },
854
+ "id": "cq53m8ZQ8ETU",
855
+ "outputId": "42f79c47-7693-41b3-8436-350cbfadddd3"
856
+ },
857
+ "execution_count": 19,
858
+ "outputs": [
859
+ {
860
+ "output_type": "stream",
861
+ "name": "stdout",
862
+ "text": [
863
+ "Accuracy of KNN model: 0.5575\n",
864
+ "Accuracy of Decision Tree model: 0.5525\n"
865
+ ]
866
+ }
867
+ ]
868
+ }
869
+ ]
870
+ }