Obotu commited on
Commit
dd20df3
·
verified ·
1 Parent(s): 8eb5ee1

Delete Medicine Recommendation System.ipynb

Browse files
Files changed (1) hide show
  1. Medicine Recommendation System.ipynb +0 -1031
Medicine Recommendation System.ipynb DELETED
@@ -1,1031 +0,0 @@
1
- {
2
- "cells": [
3
- {
4
- "cell_type": "markdown",
5
- "id": "c755214a",
6
- "metadata": {},
7
- "source": [
8
- "# Title: Personalized Medical Recommendation System with Machine Learning\n",
9
- "\n",
10
- "# Description:\n",
11
- "\n",
12
- "Welcome to our cutting-edge Personalized Medical Recommendation System, a powerful platform designed to assist users in understanding and managing their health. Leveraging the capabilities of machine learning, our system analyzes user-input symptoms to predict potential diseases accurately."
13
- ]
14
- },
15
- {
16
- "cell_type": "markdown",
17
- "id": "db119e1e",
18
- "metadata": {},
19
- "source": [
20
- "# load dataset & tools"
21
- ]
22
- },
23
- {
24
- "cell_type": "code",
25
- "execution_count": 1,
26
- "id": "4e4766bf",
27
- "metadata": {},
28
- "outputs": [],
29
- "source": [
30
- "import pandas as pd"
31
- ]
32
- },
33
- {
34
- "cell_type": "code",
35
- "execution_count": 2,
36
- "id": "56ce4778",
37
- "metadata": {},
38
- "outputs": [],
39
- "source": [
40
- "dataset = pd.read_csv('Training.csv')"
41
- ]
42
- },
43
- {
44
- "cell_type": "code",
45
- "execution_count": 3,
46
- "id": "5f18d6d2",
47
- "metadata": {},
48
- "outputs": [
49
- {
50
- "data": {
51
- "text/html": [
52
- "<div>\n",
53
- "<style scoped>\n",
54
- " .dataframe tbody tr th:only-of-type {\n",
55
- " vertical-align: middle;\n",
56
- " }\n",
57
- "\n",
58
- " .dataframe tbody tr th {\n",
59
- " vertical-align: top;\n",
60
- " }\n",
61
- "\n",
62
- " .dataframe thead th {\n",
63
- " text-align: right;\n",
64
- " }\n",
65
- "</style>\n",
66
- "<table border=\"1\" class=\"dataframe\">\n",
67
- " <thead>\n",
68
- " <tr style=\"text-align: right;\">\n",
69
- " <th></th>\n",
70
- " <th>itching</th>\n",
71
- " <th>skin_rash</th>\n",
72
- " <th>nodal_skin_eruptions</th>\n",
73
- " <th>continuous_sneezing</th>\n",
74
- " <th>shivering</th>\n",
75
- " <th>chills</th>\n",
76
- " <th>joint_pain</th>\n",
77
- " <th>stomach_pain</th>\n",
78
- " <th>acidity</th>\n",
79
- " <th>ulcers_on_tongue</th>\n",
80
- " <th>...</th>\n",
81
- " <th>blackheads</th>\n",
82
- " <th>scurring</th>\n",
83
- " <th>skin_peeling</th>\n",
84
- " <th>silver_like_dusting</th>\n",
85
- " <th>small_dents_in_nails</th>\n",
86
- " <th>inflammatory_nails</th>\n",
87
- " <th>blister</th>\n",
88
- " <th>red_sore_around_nose</th>\n",
89
- " <th>yellow_crust_ooze</th>\n",
90
- " <th>prognosis</th>\n",
91
- " </tr>\n",
92
- " </thead>\n",
93
- " <tbody>\n",
94
- " <tr>\n",
95
- " <th>0</th>\n",
96
- " <td>1</td>\n",
97
- " <td>1</td>\n",
98
- " <td>1</td>\n",
99
- " <td>0</td>\n",
100
- " <td>0</td>\n",
101
- " <td>0</td>\n",
102
- " <td>0</td>\n",
103
- " <td>0</td>\n",
104
- " <td>0</td>\n",
105
- " <td>0</td>\n",
106
- " <td>...</td>\n",
107
- " <td>0</td>\n",
108
- " <td>0</td>\n",
109
- " <td>0</td>\n",
110
- " <td>0</td>\n",
111
- " <td>0</td>\n",
112
- " <td>0</td>\n",
113
- " <td>0</td>\n",
114
- " <td>0</td>\n",
115
- " <td>0</td>\n",
116
- " <td>Fungal infection</td>\n",
117
- " </tr>\n",
118
- " <tr>\n",
119
- " <th>1</th>\n",
120
- " <td>0</td>\n",
121
- " <td>1</td>\n",
122
- " <td>1</td>\n",
123
- " <td>0</td>\n",
124
- " <td>0</td>\n",
125
- " <td>0</td>\n",
126
- " <td>0</td>\n",
127
- " <td>0</td>\n",
128
- " <td>0</td>\n",
129
- " <td>0</td>\n",
130
- " <td>...</td>\n",
131
- " <td>0</td>\n",
132
- " <td>0</td>\n",
133
- " <td>0</td>\n",
134
- " <td>0</td>\n",
135
- " <td>0</td>\n",
136
- " <td>0</td>\n",
137
- " <td>0</td>\n",
138
- " <td>0</td>\n",
139
- " <td>0</td>\n",
140
- " <td>Fungal infection</td>\n",
141
- " </tr>\n",
142
- " <tr>\n",
143
- " <th>2</th>\n",
144
- " <td>1</td>\n",
145
- " <td>0</td>\n",
146
- " <td>1</td>\n",
147
- " <td>0</td>\n",
148
- " <td>0</td>\n",
149
- " <td>0</td>\n",
150
- " <td>0</td>\n",
151
- " <td>0</td>\n",
152
- " <td>0</td>\n",
153
- " <td>0</td>\n",
154
- " <td>...</td>\n",
155
- " <td>0</td>\n",
156
- " <td>0</td>\n",
157
- " <td>0</td>\n",
158
- " <td>0</td>\n",
159
- " <td>0</td>\n",
160
- " <td>0</td>\n",
161
- " <td>0</td>\n",
162
- " <td>0</td>\n",
163
- " <td>0</td>\n",
164
- " <td>Fungal infection</td>\n",
165
- " </tr>\n",
166
- " <tr>\n",
167
- " <th>3</th>\n",
168
- " <td>1</td>\n",
169
- " <td>1</td>\n",
170
- " <td>0</td>\n",
171
- " <td>0</td>\n",
172
- " <td>0</td>\n",
173
- " <td>0</td>\n",
174
- " <td>0</td>\n",
175
- " <td>0</td>\n",
176
- " <td>0</td>\n",
177
- " <td>0</td>\n",
178
- " <td>...</td>\n",
179
- " <td>0</td>\n",
180
- " <td>0</td>\n",
181
- " <td>0</td>\n",
182
- " <td>0</td>\n",
183
- " <td>0</td>\n",
184
- " <td>0</td>\n",
185
- " <td>0</td>\n",
186
- " <td>0</td>\n",
187
- " <td>0</td>\n",
188
- " <td>Fungal infection</td>\n",
189
- " </tr>\n",
190
- " <tr>\n",
191
- " <th>4</th>\n",
192
- " <td>1</td>\n",
193
- " <td>1</td>\n",
194
- " <td>1</td>\n",
195
- " <td>0</td>\n",
196
- " <td>0</td>\n",
197
- " <td>0</td>\n",
198
- " <td>0</td>\n",
199
- " <td>0</td>\n",
200
- " <td>0</td>\n",
201
- " <td>0</td>\n",
202
- " <td>...</td>\n",
203
- " <td>0</td>\n",
204
- " <td>0</td>\n",
205
- " <td>0</td>\n",
206
- " <td>0</td>\n",
207
- " <td>0</td>\n",
208
- " <td>0</td>\n",
209
- " <td>0</td>\n",
210
- " <td>0</td>\n",
211
- " <td>0</td>\n",
212
- " <td>Fungal infection</td>\n",
213
- " </tr>\n",
214
- " <tr>\n",
215
- " <th>...</th>\n",
216
- " <td>...</td>\n",
217
- " <td>...</td>\n",
218
- " <td>...</td>\n",
219
- " <td>...</td>\n",
220
- " <td>...</td>\n",
221
- " <td>...</td>\n",
222
- " <td>...</td>\n",
223
- " <td>...</td>\n",
224
- " <td>...</td>\n",
225
- " <td>...</td>\n",
226
- " <td>...</td>\n",
227
- " <td>...</td>\n",
228
- " <td>...</td>\n",
229
- " <td>...</td>\n",
230
- " <td>...</td>\n",
231
- " <td>...</td>\n",
232
- " <td>...</td>\n",
233
- " <td>...</td>\n",
234
- " <td>...</td>\n",
235
- " <td>...</td>\n",
236
- " <td>...</td>\n",
237
- " </tr>\n",
238
- " <tr>\n",
239
- " <th>4915</th>\n",
240
- " <td>0</td>\n",
241
- " <td>0</td>\n",
242
- " <td>0</td>\n",
243
- " <td>0</td>\n",
244
- " <td>0</td>\n",
245
- " <td>0</td>\n",
246
- " <td>0</td>\n",
247
- " <td>0</td>\n",
248
- " <td>0</td>\n",
249
- " <td>0</td>\n",
250
- " <td>...</td>\n",
251
- " <td>0</td>\n",
252
- " <td>0</td>\n",
253
- " <td>0</td>\n",
254
- " <td>0</td>\n",
255
- " <td>0</td>\n",
256
- " <td>0</td>\n",
257
- " <td>0</td>\n",
258
- " <td>0</td>\n",
259
- " <td>0</td>\n",
260
- " <td>(vertigo) Paroymsal Positional Vertigo</td>\n",
261
- " </tr>\n",
262
- " <tr>\n",
263
- " <th>4916</th>\n",
264
- " <td>0</td>\n",
265
- " <td>1</td>\n",
266
- " <td>0</td>\n",
267
- " <td>0</td>\n",
268
- " <td>0</td>\n",
269
- " <td>0</td>\n",
270
- " <td>0</td>\n",
271
- " <td>0</td>\n",
272
- " <td>0</td>\n",
273
- " <td>0</td>\n",
274
- " <td>...</td>\n",
275
- " <td>1</td>\n",
276
- " <td>1</td>\n",
277
- " <td>0</td>\n",
278
- " <td>0</td>\n",
279
- " <td>0</td>\n",
280
- " <td>0</td>\n",
281
- " <td>0</td>\n",
282
- " <td>0</td>\n",
283
- " <td>0</td>\n",
284
- " <td>Acne</td>\n",
285
- " </tr>\n",
286
- " <tr>\n",
287
- " <th>4917</th>\n",
288
- " <td>0</td>\n",
289
- " <td>0</td>\n",
290
- " <td>0</td>\n",
291
- " <td>0</td>\n",
292
- " <td>0</td>\n",
293
- " <td>0</td>\n",
294
- " <td>0</td>\n",
295
- " <td>0</td>\n",
296
- " <td>0</td>\n",
297
- " <td>0</td>\n",
298
- " <td>...</td>\n",
299
- " <td>0</td>\n",
300
- " <td>0</td>\n",
301
- " <td>0</td>\n",
302
- " <td>0</td>\n",
303
- " <td>0</td>\n",
304
- " <td>0</td>\n",
305
- " <td>0</td>\n",
306
- " <td>0</td>\n",
307
- " <td>0</td>\n",
308
- " <td>Urinary tract infection</td>\n",
309
- " </tr>\n",
310
- " <tr>\n",
311
- " <th>4918</th>\n",
312
- " <td>0</td>\n",
313
- " <td>1</td>\n",
314
- " <td>0</td>\n",
315
- " <td>0</td>\n",
316
- " <td>0</td>\n",
317
- " <td>0</td>\n",
318
- " <td>1</td>\n",
319
- " <td>0</td>\n",
320
- " <td>0</td>\n",
321
- " <td>0</td>\n",
322
- " <td>...</td>\n",
323
- " <td>0</td>\n",
324
- " <td>0</td>\n",
325
- " <td>1</td>\n",
326
- " <td>1</td>\n",
327
- " <td>1</td>\n",
328
- " <td>1</td>\n",
329
- " <td>0</td>\n",
330
- " <td>0</td>\n",
331
- " <td>0</td>\n",
332
- " <td>Psoriasis</td>\n",
333
- " </tr>\n",
334
- " <tr>\n",
335
- " <th>4919</th>\n",
336
- " <td>0</td>\n",
337
- " <td>1</td>\n",
338
- " <td>0</td>\n",
339
- " <td>0</td>\n",
340
- " <td>0</td>\n",
341
- " <td>0</td>\n",
342
- " <td>0</td>\n",
343
- " <td>0</td>\n",
344
- " <td>0</td>\n",
345
- " <td>0</td>\n",
346
- " <td>...</td>\n",
347
- " <td>0</td>\n",
348
- " <td>0</td>\n",
349
- " <td>0</td>\n",
350
- " <td>0</td>\n",
351
- " <td>0</td>\n",
352
- " <td>0</td>\n",
353
- " <td>1</td>\n",
354
- " <td>1</td>\n",
355
- " <td>1</td>\n",
356
- " <td>Impetigo</td>\n",
357
- " </tr>\n",
358
- " </tbody>\n",
359
- "</table>\n",
360
- "<p>4920 rows × 133 columns</p>\n",
361
- "</div>"
362
- ],
363
- "text/plain": [
364
- " itching skin_rash nodal_skin_eruptions continuous_sneezing \\\n",
365
- "0 1 1 1 0 \n",
366
- "1 0 1 1 0 \n",
367
- "2 1 0 1 0 \n",
368
- "3 1 1 0 0 \n",
369
- "4 1 1 1 0 \n",
370
- "... ... ... ... ... \n",
371
- "4915 0 0 0 0 \n",
372
- "4916 0 1 0 0 \n",
373
- "4917 0 0 0 0 \n",
374
- "4918 0 1 0 0 \n",
375
- "4919 0 1 0 0 \n",
376
- "\n",
377
- " shivering chills joint_pain stomach_pain acidity ulcers_on_tongue \\\n",
378
- "0 0 0 0 0 0 0 \n",
379
- "1 0 0 0 0 0 0 \n",
380
- "2 0 0 0 0 0 0 \n",
381
- "3 0 0 0 0 0 0 \n",
382
- "4 0 0 0 0 0 0 \n",
383
- "... ... ... ... ... ... ... \n",
384
- "4915 0 0 0 0 0 0 \n",
385
- "4916 0 0 0 0 0 0 \n",
386
- "4917 0 0 0 0 0 0 \n",
387
- "4918 0 0 1 0 0 0 \n",
388
- "4919 0 0 0 0 0 0 \n",
389
- "\n",
390
- " ... blackheads scurring skin_peeling silver_like_dusting \\\n",
391
- "0 ... 0 0 0 0 \n",
392
- "1 ... 0 0 0 0 \n",
393
- "2 ... 0 0 0 0 \n",
394
- "3 ... 0 0 0 0 \n",
395
- "4 ... 0 0 0 0 \n",
396
- "... ... ... ... ... ... \n",
397
- "4915 ... 0 0 0 0 \n",
398
- "4916 ... 1 1 0 0 \n",
399
- "4917 ... 0 0 0 0 \n",
400
- "4918 ... 0 0 1 1 \n",
401
- "4919 ... 0 0 0 0 \n",
402
- "\n",
403
- " small_dents_in_nails inflammatory_nails blister red_sore_around_nose \\\n",
404
- "0 0 0 0 0 \n",
405
- "1 0 0 0 0 \n",
406
- "2 0 0 0 0 \n",
407
- "3 0 0 0 0 \n",
408
- "4 0 0 0 0 \n",
409
- "... ... ... ... ... \n",
410
- "4915 0 0 0 0 \n",
411
- "4916 0 0 0 0 \n",
412
- "4917 0 0 0 0 \n",
413
- "4918 1 1 0 0 \n",
414
- "4919 0 0 1 1 \n",
415
- "\n",
416
- " yellow_crust_ooze prognosis \n",
417
- "0 0 Fungal infection \n",
418
- "1 0 Fungal infection \n",
419
- "2 0 Fungal infection \n",
420
- "3 0 Fungal infection \n",
421
- "4 0 Fungal infection \n",
422
- "... ... ... \n",
423
- "4915 0 (vertigo) Paroymsal Positional Vertigo \n",
424
- "4916 0 Acne \n",
425
- "4917 0 Urinary tract infection \n",
426
- "4918 0 Psoriasis \n",
427
- "4919 1 Impetigo \n",
428
- "\n",
429
- "[4920 rows x 133 columns]"
430
- ]
431
- },
432
- "execution_count": 3,
433
- "metadata": {},
434
- "output_type": "execute_result"
435
- }
436
- ],
437
- "source": [
438
- "dataset"
439
- ]
440
- },
441
- {
442
- "cell_type": "code",
443
- "execution_count": 4,
444
- "id": "f49b2b12",
445
- "metadata": {},
446
- "outputs": [],
447
- "source": [
448
- "# vals = dataset.values.flatten()"
449
- ]
450
- },
451
- {
452
- "cell_type": "code",
453
- "execution_count": 5,
454
- "id": "a49049bd",
455
- "metadata": {},
456
- "outputs": [
457
- {
458
- "data": {
459
- "text/plain": [
460
- "(4920, 133)"
461
- ]
462
- },
463
- "execution_count": 5,
464
- "metadata": {},
465
- "output_type": "execute_result"
466
- }
467
- ],
468
- "source": [
469
- "dataset.shape"
470
- ]
471
- },
472
- {
473
- "cell_type": "markdown",
474
- "id": "2db916ab",
475
- "metadata": {},
476
- "source": [
477
- "# train test split"
478
- ]
479
- },
480
- {
481
- "cell_type": "code",
482
- "execution_count": 15,
483
- "id": "b1e9c647",
484
- "metadata": {},
485
- "outputs": [],
486
- "source": [
487
- "from sklearn.model_selection import train_test_split\n",
488
- "from sklearn.preprocessing import LabelEncoder"
489
- ]
490
- },
491
- {
492
- "cell_type": "code",
493
- "execution_count": 16,
494
- "id": "4cb2e972",
495
- "metadata": {},
496
- "outputs": [],
497
- "source": [
498
- "X = dataset.drop('prognosis', axis=1)\n",
499
- "y = dataset['prognosis']\n",
500
- "\n",
501
- "# ecoding prognonsis\n",
502
- "le = LabelEncoder()\n",
503
- "le.fit(y)\n",
504
- "Y = le.transform(y)\n",
505
- " \n",
506
- "X_train, X_test, y_train, y_test = train_test_split(X, Y, test_size=0.3, random_state=20)"
507
- ]
508
- },
509
- {
510
- "cell_type": "markdown",
511
- "id": "1c1a9ed2",
512
- "metadata": {},
513
- "source": [
514
- "# Training top models"
515
- ]
516
- },
517
- {
518
- "cell_type": "code",
519
- "execution_count": 8,
520
- "id": "5b9c4a9e",
521
- "metadata": {},
522
- "outputs": [
523
- {
524
- "name": "stdout",
525
- "output_type": "stream",
526
- "text": [
527
- "SVC Accuracy: 1.0\n",
528
- "SVC Confusion Matrix:\n",
529
- "[[40, 0, 0, ..., 0, 0, 0],\n",
530
- " [ 0, 43, 0, ..., 0, 0, 0],\n",
531
- " [ 0, 0, 28, ..., 0, 0, 0],\n",
532
- " ...,\n",
533
- " [ 0, 0, 0, ..., 34, 0, 0],\n",
534
- " [ 0, 0, 0, ..., 0, 41, 0],\n",
535
- " [ 0, 0, 0, ..., 0, 0, 31]]\n",
536
- "\n",
537
- "========================================\n",
538
- "\n",
539
- "RandomForest Accuracy: 1.0\n",
540
- "RandomForest Confusion Matrix:\n",
541
- "[[40, 0, 0, ..., 0, 0, 0],\n",
542
- " [ 0, 43, 0, ..., 0, 0, 0],\n",
543
- " [ 0, 0, 28, ..., 0, 0, 0],\n",
544
- " ...,\n",
545
- " [ 0, 0, 0, ..., 34, 0, 0],\n",
546
- " [ 0, 0, 0, ..., 0, 41, 0],\n",
547
- " [ 0, 0, 0, ..., 0, 0, 31]]\n",
548
- "\n",
549
- "========================================\n",
550
- "\n",
551
- "GradientBoosting Accuracy: 1.0\n",
552
- "GradientBoosting Confusion Matrix:\n",
553
- "[[40, 0, 0, ..., 0, 0, 0],\n",
554
- " [ 0, 43, 0, ..., 0, 0, 0],\n",
555
- " [ 0, 0, 28, ..., 0, 0, 0],\n",
556
- " ...,\n",
557
- " [ 0, 0, 0, ..., 34, 0, 0],\n",
558
- " [ 0, 0, 0, ..., 0, 41, 0],\n",
559
- " [ 0, 0, 0, ..., 0, 0, 31]]\n",
560
- "\n",
561
- "========================================\n",
562
- "\n",
563
- "KNeighbors Accuracy: 1.0\n",
564
- "KNeighbors Confusion Matrix:\n",
565
- "[[40, 0, 0, ..., 0, 0, 0],\n",
566
- " [ 0, 43, 0, ..., 0, 0, 0],\n",
567
- " [ 0, 0, 28, ..., 0, 0, 0],\n",
568
- " ...,\n",
569
- " [ 0, 0, 0, ..., 34, 0, 0],\n",
570
- " [ 0, 0, 0, ..., 0, 41, 0],\n",
571
- " [ 0, 0, 0, ..., 0, 0, 31]]\n",
572
- "\n",
573
- "========================================\n",
574
- "\n",
575
- "MultinomialNB Accuracy: 1.0\n",
576
- "MultinomialNB Confusion Matrix:\n",
577
- "[[40, 0, 0, ..., 0, 0, 0],\n",
578
- " [ 0, 43, 0, ..., 0, 0, 0],\n",
579
- " [ 0, 0, 28, ..., 0, 0, 0],\n",
580
- " ...,\n",
581
- " [ 0, 0, 0, ..., 34, 0, 0],\n",
582
- " [ 0, 0, 0, ..., 0, 41, 0],\n",
583
- " [ 0, 0, 0, ..., 0, 0, 31]]\n",
584
- "\n",
585
- "========================================\n",
586
- "\n"
587
- ]
588
- }
589
- ],
590
- "source": [
591
- "from sklearn.datasets import make_classification\n",
592
- "from sklearn.model_selection import train_test_split\n",
593
- "from sklearn.svm import SVC\n",
594
- "from sklearn.ensemble import RandomForestClassifier, GradientBoostingClassifier\n",
595
- "from sklearn.neighbors import KNeighborsClassifier\n",
596
- "from sklearn.naive_bayes import MultinomialNB\n",
597
- "from sklearn.metrics import accuracy_score, confusion_matrix\n",
598
- "import numpy as np\n",
599
- "\n",
600
- "\n",
601
- "# Create a dictionary to store models\n",
602
- "models = {\n",
603
- " 'SVC': SVC(kernel='linear'),\n",
604
- " 'RandomForest': RandomForestClassifier(n_estimators=100, random_state=42),\n",
605
- " 'GradientBoosting': GradientBoostingClassifier(n_estimators=100, random_state=42),\n",
606
- " 'KNeighbors': KNeighborsClassifier(n_neighbors=5),\n",
607
- " 'MultinomialNB': MultinomialNB()\n",
608
- "}\n",
609
- "\n",
610
- "# Loop through the models, train, test, and print results\n",
611
- "for model_name, model in models.items():\n",
612
- " # Train the model\n",
613
- " model.fit(X_train, y_train)\n",
614
- "\n",
615
- " # Test the model\n",
616
- " predictions = model.predict(X_test)\n",
617
- "\n",
618
- " # Calculate accuracy\n",
619
- " accuracy = accuracy_score(y_test, predictions)\n",
620
- " print(f\"{model_name} Accuracy: {accuracy}\")\n",
621
- "\n",
622
- " # Calculate confusion matrix\n",
623
- " cm = confusion_matrix(y_test, predictions)\n",
624
- " print(f\"{model_name} Confusion Matrix:\")\n",
625
- " print(np.array2string(cm, separator=', '))\n",
626
- "\n",
627
- " print(\"\\n\" + \"=\"*40 + \"\\n\")\n"
628
- ]
629
- },
630
- {
631
- "cell_type": "markdown",
632
- "id": "36cee3c8",
633
- "metadata": {},
634
- "source": [
635
- "# single prediction"
636
- ]
637
- },
638
- {
639
- "cell_type": "code",
640
- "execution_count": 18,
641
- "id": "a74ad639",
642
- "metadata": {},
643
- "outputs": [
644
- {
645
- "data": {
646
- "text/plain": [
647
- "1.0"
648
- ]
649
- },
650
- "execution_count": 18,
651
- "metadata": {},
652
- "output_type": "execute_result"
653
- }
654
- ],
655
- "source": [
656
- "# selecting svc\n",
657
- "svc = SVC(kernel='linear')\n",
658
- "svc.fit(X_train,y_train)\n",
659
- "ypred = svc.predict(X_test)\n",
660
- "accuracy_score(y_test,ypred)"
661
- ]
662
- },
663
- {
664
- "cell_type": "code",
665
- "execution_count": 114,
666
- "id": "fdd98daa",
667
- "metadata": {},
668
- "outputs": [],
669
- "source": [
670
- "# save svc\n",
671
- "import pickle\n",
672
- "pickle.dump(svc,open('svc.pkl','wb'))"
673
- ]
674
- },
675
- {
676
- "cell_type": "code",
677
- "execution_count": 115,
678
- "id": "4dd13145",
679
- "metadata": {},
680
- "outputs": [],
681
- "source": [
682
- "# load model\n",
683
- "svc = pickle.load(open('svc.pkl','rb'))"
684
- ]
685
- },
686
- {
687
- "cell_type": "code",
688
- "execution_count": 116,
689
- "id": "8bf40f9d",
690
- "metadata": {},
691
- "outputs": [
692
- {
693
- "name": "stdout",
694
- "output_type": "stream",
695
- "text": [
696
- "predicted disease : [40]\n",
697
- "Actual Disease : 40\n"
698
- ]
699
- },
700
- {
701
- "name": "stderr",
702
- "output_type": "stream",
703
- "text": [
704
- "C:\\Users\\naimat\\anaconda3\\lib\\site-packages\\sklearn\\base.py:465: UserWarning: X does not have valid feature names, but SVC was fitted with feature names\n",
705
- " warnings.warn(\n"
706
- ]
707
- }
708
- ],
709
- "source": [
710
- "# test 1:\n",
711
- "print(\"predicted disease :\",svc.predict(X_test.iloc[0].values.reshape(1,-1)))\n",
712
- "print(\"Actual Disease :\", y_test[0])"
713
- ]
714
- },
715
- {
716
- "cell_type": "code",
717
- "execution_count": 117,
718
- "id": "786bfd1a",
719
- "metadata": {},
720
- "outputs": [
721
- {
722
- "name": "stdout",
723
- "output_type": "stream",
724
- "text": [
725
- "predicted disease : [39]\n",
726
- "Actual Disease : 39\n"
727
- ]
728
- },
729
- {
730
- "name": "stderr",
731
- "output_type": "stream",
732
- "text": [
733
- "C:\\Users\\naimat\\anaconda3\\lib\\site-packages\\sklearn\\base.py:465: UserWarning: X does not have valid feature names, but SVC was fitted with feature names\n",
734
- " warnings.warn(\n"
735
- ]
736
- }
737
- ],
738
- "source": [
739
- "# test 2:\n",
740
- "print(\"predicted disease :\",svc.predict(X_test.iloc[100].values.reshape(1,-1)))\n",
741
- "print(\"Actual Disease :\", y_test[100])"
742
- ]
743
- },
744
- {
745
- "cell_type": "markdown",
746
- "id": "9ce6884a",
747
- "metadata": {},
748
- "source": [
749
- "# Recommendation System and Prediction"
750
- ]
751
- },
752
- {
753
- "cell_type": "markdown",
754
- "id": "f53f59b8",
755
- "metadata": {},
756
- "source": [
757
- "# load database and use logic for recommendations"
758
- ]
759
- },
760
- {
761
- "cell_type": "code",
762
- "execution_count": 118,
763
- "id": "767ed813",
764
- "metadata": {},
765
- "outputs": [],
766
- "source": [
767
- "sym_des = pd.read_csv(\"symtoms_df.csv\")\n",
768
- "precautions = pd.read_csv(\"precautions_df.csv\")\n",
769
- "workout = pd.read_csv(\"workout_df.csv\")\n",
770
- "description = pd.read_csv(\"description.csv\")\n",
771
- "medications = pd.read_csv('medications.csv')\n",
772
- "diets = pd.read_csv(\"diets.csv\")"
773
- ]
774
- },
775
- {
776
- "cell_type": "code",
777
- "execution_count": 119,
778
- "id": "6cb123a9",
779
- "metadata": {},
780
- "outputs": [],
781
- "source": [
782
- "#============================================================\n",
783
- "# custome and helping functions\n",
784
- "#==========================helper funtions================\n",
785
- "def helper(dis):\n",
786
- " desc = description[description['Disease'] == predicted_disease]['Description']\n",
787
- " desc = \" \".join([w for w in desc])\n",
788
- "\n",
789
- " pre = precautions[precautions['Disease'] == dis][['Precaution_1', 'Precaution_2', 'Precaution_3', 'Precaution_4']]\n",
790
- " pre = [col for col in pre.values]\n",
791
- "\n",
792
- " med = medications[medications['Disease'] == dis]['Medication']\n",
793
- " med = [med for med in med.values]\n",
794
- "\n",
795
- " die = diets[diets['Disease'] == dis]['Diet']\n",
796
- " die = [die for die in die.values]\n",
797
- "\n",
798
- " wrkout = workout[workout['disease'] == dis] ['workout']\n",
799
- "\n",
800
- "\n",
801
- " return desc,pre,med,die,wrkout\n",
802
- "\n",
803
- "symptoms_dict = {'itching': 0, 'skin_rash': 1, 'nodal_skin_eruptions': 2, 'continuous_sneezing': 3, 'shivering': 4, 'chills': 5, 'joint_pain': 6, 'stomach_pain': 7, 'acidity': 8, 'ulcers_on_tongue': 9, 'muscle_wasting': 10, 'vomiting': 11, 'burning_micturition': 12, 'spotting_ urination': 13, 'fatigue': 14, 'weight_gain': 15, 'anxiety': 16, 'cold_hands_and_feets': 17, 'mood_swings': 18, 'weight_loss': 19, 'restlessness': 20, 'lethargy': 21, 'patches_in_throat': 22, 'irregular_sugar_level': 23, 'cough': 24, 'high_fever': 25, 'sunken_eyes': 26, 'breathlessness': 27, 'sweating': 28, 'dehydration': 29, 'indigestion': 30, 'headache': 31, 'yellowish_skin': 32, 'dark_urine': 33, 'nausea': 34, 'loss_of_appetite': 35, 'pain_behind_the_eyes': 36, 'back_pain': 37, 'constipation': 38, 'abdominal_pain': 39, 'diarrhoea': 40, 'mild_fever': 41, 'yellow_urine': 42, 'yellowing_of_eyes': 43, 'acute_liver_failure': 44, 'fluid_overload': 45, 'swelling_of_stomach': 46, 'swelled_lymph_nodes': 47, 'malaise': 48, 'blurred_and_distorted_vision': 49, 'phlegm': 50, 'throat_irritation': 51, 'redness_of_eyes': 52, 'sinus_pressure': 53, 'runny_nose': 54, 'congestion': 55, 'chest_pain': 56, 'weakness_in_limbs': 57, 'fast_heart_rate': 58, 'pain_during_bowel_movements': 59, 'pain_in_anal_region': 60, 'bloody_stool': 61, 'irritation_in_anus': 62, 'neck_pain': 63, 'dizziness': 64, 'cramps': 65, 'bruising': 66, 'obesity': 67, 'swollen_legs': 68, 'swollen_blood_vessels': 69, 'puffy_face_and_eyes': 70, 'enlarged_thyroid': 71, 'brittle_nails': 72, 'swollen_extremeties': 73, 'excessive_hunger': 74, 'extra_marital_contacts': 75, 'drying_and_tingling_lips': 76, 'slurred_speech': 77, 'knee_pain': 78, 'hip_joint_pain': 79, 'muscle_weakness': 80, 'stiff_neck': 81, 'swelling_joints': 82, 'movement_stiffness': 83, 'spinning_movements': 84, 'loss_of_balance': 85, 'unsteadiness': 86, 'weakness_of_one_body_side': 87, 'loss_of_smell': 88, 'bladder_discomfort': 89, 'foul_smell_of urine': 90, 'continuous_feel_of_urine': 91, 'passage_of_gases': 92, 'internal_itching': 93, 'toxic_look_(typhos)': 94, 'depression': 95, 'irritability': 96, 'muscle_pain': 97, 'altered_sensorium': 98, 'red_spots_over_body': 99, 'belly_pain': 100, 'abnormal_menstruation': 101, 'dischromic _patches': 102, 'watering_from_eyes': 103, 'increased_appetite': 104, 'polyuria': 105, 'family_history': 106, 'mucoid_sputum': 107, 'rusty_sputum': 108, 'lack_of_concentration': 109, 'visual_disturbances': 110, 'receiving_blood_transfusion': 111, 'receiving_unsterile_injections': 112, 'coma': 113, 'stomach_bleeding': 114, 'distention_of_abdomen': 115, 'history_of_alcohol_consumption': 116, 'fluid_overload.1': 117, 'blood_in_sputum': 118, 'prominent_veins_on_calf': 119, 'palpitations': 120, 'painful_walking': 121, 'pus_filled_pimples': 122, 'blackheads': 123, 'scurring': 124, 'skin_peeling': 125, 'silver_like_dusting': 126, 'small_dents_in_nails': 127, 'inflammatory_nails': 128, 'blister': 129, 'red_sore_around_nose': 130, 'yellow_crust_ooze': 131}\n",
804
- "diseases_list = {15: 'Fungal infection', 4: 'Allergy', 16: 'GERD', 9: 'Chronic cholestasis', 14: 'Drug Reaction', 33: 'Peptic ulcer diseae', 1: 'AIDS', 12: 'Diabetes ', 17: 'Gastroenteritis', 6: 'Bronchial Asthma', 23: 'Hypertension ', 30: 'Migraine', 7: 'Cervical spondylosis', 32: 'Paralysis (brain hemorrhage)', 28: 'Jaundice', 29: 'Malaria', 8: 'Chicken pox', 11: 'Dengue', 37: 'Typhoid', 40: 'hepatitis A', 19: 'Hepatitis B', 20: 'Hepatitis C', 21: 'Hepatitis D', 22: 'Hepatitis E', 3: 'Alcoholic hepatitis', 36: 'Tuberculosis', 10: 'Common Cold', 34: 'Pneumonia', 13: 'Dimorphic hemmorhoids(piles)', 18: 'Heart attack', 39: 'Varicose veins', 26: 'Hypothyroidism', 24: 'Hyperthyroidism', 25: 'Hypoglycemia', 31: 'Osteoarthristis', 5: 'Arthritis', 0: '(vertigo) Paroymsal Positional Vertigo', 2: 'Acne', 38: 'Urinary tract infection', 35: 'Psoriasis', 27: 'Impetigo'}\n",
805
- "\n",
806
- "# Model Prediction function\n",
807
- "def get_predicted_value(patient_symptoms):\n",
808
- " input_vector = np.zeros(len(symptoms_dict))\n",
809
- " for item in patient_symptoms:\n",
810
- " input_vector[symptoms_dict[item]] = 1\n",
811
- " return diseases_list[svc.predict([input_vector])[0]]"
812
- ]
813
- },
814
- {
815
- "cell_type": "code",
816
- "execution_count": 121,
817
- "id": "a36b1e93",
818
- "metadata": {},
819
- "outputs": [
820
- {
821
- "name": "stdout",
822
- "output_type": "stream",
823
- "text": [
824
- "Enter your symptoms.......itching,skin_rash,nodal_skin_eruptions\n",
825
- "=================predicted disease============\n",
826
- "Fungal infection\n",
827
- "=================description==================\n",
828
- "Fungal infection is a common skin condition caused by fungi.\n",
829
- "=================precautions==================\n",
830
- "1 : bath twice\n",
831
- "2 : use detol or neem in bathing water\n",
832
- "3 : keep infected area dry\n",
833
- "4 : use clean cloths\n",
834
- "=================medications==================\n",
835
- "5 : ['Antifungal Cream', 'Fluconazole', 'Terbinafine', 'Clotrimazole', 'Ketoconazole']\n",
836
- "=================workout==================\n",
837
- "6 : Avoid sugary foods\n",
838
- "7 : Consume probiotics\n",
839
- "8 : Increase intake of garlic\n",
840
- "9 : Include yogurt in diet\n",
841
- "10 : Limit processed foods\n",
842
- "11 : Stay hydrated\n",
843
- "12 : Consume green tea\n",
844
- "13 : Eat foods rich in zinc\n",
845
- "14 : Include turmeric in diet\n",
846
- "15 : Eat fruits and vegetables\n",
847
- "=================diets==================\n",
848
- "16 : ['Antifungal Diet', 'Probiotics', 'Garlic', 'Coconut oil', 'Turmeric']\n"
849
- ]
850
- },
851
- {
852
- "name": "stderr",
853
- "output_type": "stream",
854
- "text": [
855
- "C:\\Users\\naimat\\anaconda3\\lib\\site-packages\\sklearn\\base.py:465: UserWarning: X does not have valid feature names, but SVC was fitted with feature names\n",
856
- " warnings.warn(\n"
857
- ]
858
- }
859
- ],
860
- "source": [
861
- "# Test 1\n",
862
- "# Split the user's input into a list of symptoms (assuming they are comma-separated) # itching,skin_rash,nodal_skin_eruptions\n",
863
- "symptoms = input(\"Enter your symptoms.......\")\n",
864
- "user_symptoms = [s.strip() for s in symptoms.split(',')]\n",
865
- "# Remove any extra characters, if any\n",
866
- "user_symptoms = [symptom.strip(\"[]' \") for symptom in user_symptoms]\n",
867
- "predicted_disease = get_predicted_value(user_symptoms)\n",
868
- "\n",
869
- "desc, pre, med, die, wrkout = helper(predicted_disease)\n",
870
- "\n",
871
- "print(\"=================predicted disease============\")\n",
872
- "print(predicted_disease)\n",
873
- "print(\"=================description==================\")\n",
874
- "print(desc)\n",
875
- "print(\"=================precautions==================\")\n",
876
- "i = 1\n",
877
- "for p_i in pre[0]:\n",
878
- " print(i, \": \", p_i)\n",
879
- " i += 1\n",
880
- "\n",
881
- "print(\"=================medications==================\")\n",
882
- "for m_i in med:\n",
883
- " print(i, \": \", m_i)\n",
884
- " i += 1\n",
885
- "\n",
886
- "print(\"=================workout==================\")\n",
887
- "for w_i in wrkout:\n",
888
- " print(i, \": \", w_i)\n",
889
- " i += 1\n",
890
- "\n",
891
- "print(\"=================diets==================\")\n",
892
- "for d_i in die:\n",
893
- " print(i, \": \", d_i)\n",
894
- " i += 1\n"
895
- ]
896
- },
897
- {
898
- "cell_type": "code",
899
- "execution_count": 122,
900
- "id": "2d7ee79b",
901
- "metadata": {},
902
- "outputs": [
903
- {
904
- "name": "stdout",
905
- "output_type": "stream",
906
- "text": [
907
- "Enter your symptoms.......yellow_crust_ooze,red_sore_around_nose,small_dents_in_nails,inflammatory_nails,blister\n",
908
- "=================predicted disease============\n",
909
- "Impetigo\n",
910
- "=================description==================\n",
911
- "Impetigo is a highly contagious skin infection causing red sores that can break open.\n",
912
- "=================precautions==================\n",
913
- "1 : soak affected area in warm water\n",
914
- "2 : use antibiotics\n",
915
- "3 : remove scabs with wet compressed cloth\n",
916
- "4 : consult doctor\n",
917
- "=================medications==================\n",
918
- "5 : ['Topical antibiotics', 'Oral antibiotics', 'Antiseptics', 'Ointments', 'Warm compresses']\n",
919
- "=================workout==================\n",
920
- "6 : Maintain good hygiene\n",
921
- "7 : Stay hydrated\n",
922
- "8 : Consume nutrient-rich foods\n",
923
- "9 : Limit sugary foods and beverages\n",
924
- "10 : Include foods rich in vitamin C\n",
925
- "11 : Consult a healthcare professional\n",
926
- "12 : Follow medical recommendations\n",
927
- "13 : Avoid scratching\n",
928
- "14 : Take prescribed antibiotics\n",
929
- "15 : Practice wound care\n",
930
- "=================diets==================\n",
931
- "16 : ['Impetigo Diet', 'Antibiotic treatment', 'Fruits and vegetables', 'Hydration', 'Protein-rich foods']\n"
932
- ]
933
- },
934
- {
935
- "name": "stderr",
936
- "output_type": "stream",
937
- "text": [
938
- "C:\\Users\\naimat\\anaconda3\\lib\\site-packages\\sklearn\\base.py:465: UserWarning: X does not have valid feature names, but SVC was fitted with feature names\n",
939
- " warnings.warn(\n"
940
- ]
941
- }
942
- ],
943
- "source": [
944
- "# Test 1\n",
945
- "# Split the user's input into a list of symptoms (assuming they are comma-separated) # yellow_crust_ooze,red_sore_around_nose,small_dents_in_nails,inflammatory_nails,blister\n",
946
- "symptoms = input(\"Enter your symptoms.......\")\n",
947
- "user_symptoms = [s.strip() for s in symptoms.split(',')]\n",
948
- "# Remove any extra characters, if any\n",
949
- "user_symptoms = [symptom.strip(\"[]' \") for symptom in user_symptoms]\n",
950
- "predicted_disease = get_predicted_value(user_symptoms)\n",
951
- "\n",
952
- "desc, pre, med, die, wrkout = helper(predicted_disease)\n",
953
- "\n",
954
- "print(\"=================predicted disease============\")\n",
955
- "print(predicted_disease)\n",
956
- "print(\"=================description==================\")\n",
957
- "print(desc)\n",
958
- "print(\"=================precautions==================\")\n",
959
- "i = 1\n",
960
- "for p_i in pre[0]:\n",
961
- " print(i, \": \", p_i)\n",
962
- " i += 1\n",
963
- "\n",
964
- "print(\"=================medications==================\")\n",
965
- "for m_i in med:\n",
966
- " print(i, \": \", m_i)\n",
967
- " i += 1\n",
968
- "\n",
969
- "print(\"=================workout==================\")\n",
970
- "for w_i in wrkout:\n",
971
- " print(i, \": \", w_i)\n",
972
- " i += 1\n",
973
- "\n",
974
- "print(\"=================diets==================\")\n",
975
- "for d_i in die:\n",
976
- " print(i, \": \", d_i)\n",
977
- " i += 1\n"
978
- ]
979
- },
980
- {
981
- "cell_type": "code",
982
- "execution_count": 123,
983
- "id": "a8d5df35",
984
- "metadata": {},
985
- "outputs": [
986
- {
987
- "name": "stdout",
988
- "output_type": "stream",
989
- "text": [
990
- "1.3.2\n"
991
- ]
992
- }
993
- ],
994
- "source": [
995
- "# let's use pycharm flask app\n",
996
- "# but install this version in pycharm\n",
997
- "import sklearn\n",
998
- "print(sklearn.__version__)"
999
- ]
1000
- },
1001
- {
1002
- "cell_type": "code",
1003
- "execution_count": null,
1004
- "id": "97dfb973",
1005
- "metadata": {},
1006
- "outputs": [],
1007
- "source": []
1008
- }
1009
- ],
1010
- "metadata": {
1011
- "kernelspec": {
1012
- "display_name": "Python 3 (ipykernel)",
1013
- "language": "python",
1014
- "name": "python3"
1015
- },
1016
- "language_info": {
1017
- "codemirror_mode": {
1018
- "name": "ipython",
1019
- "version": 3
1020
- },
1021
- "file_extension": ".py",
1022
- "mimetype": "text/x-python",
1023
- "name": "python",
1024
- "nbconvert_exporter": "python",
1025
- "pygments_lexer": "ipython3",
1026
- "version": "3.9.12"
1027
- }
1028
- },
1029
- "nbformat": 4,
1030
- "nbformat_minor": 5
1031
- }