forked from Lakhankumawat/LearnCPP
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathH
More file actions
4875 lines (4875 loc) · 241 KB
/
H
File metadata and controls
4875 lines (4875 loc) · 241 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
{
"nbformat": 4,
"nbformat_minor": 0,
"metadata": {
"colab": {
"provenance": [],
"include_colab_link": true
},
"kernelspec": {
"name": "python3",
"display_name": "Python 3"
},
"language_info": {
"name": "python"
}
},
"cells": [
{
"cell_type": "markdown",
"metadata": {
"id": "view-in-github",
"colab_type": "text"
},
"source": [
"<a href=\"https://colab.research.google.com/github/ZeyTrack/LearnCPP/blob/main/Heart_Attack_Risk_Analysis.ipynb\" target=\"_parent\"><img src=\"https://colab.research.google.com/assets/colab-badge.svg\" alt=\"Open In Colab\"/></a>"
]
},
{
"cell_type": "markdown",
"source": [
"#Heart Attack Risk Analysis\n",
"##### Predict whether patients are at high or low risk of heart attacks."
],
"metadata": {
"id": "3BBH0bnJ-fbd"
}
},
{
"cell_type": "markdown",
"source": [
"This dataset provides a comprehensive array of features relevant to heart health and lifestyle choices, encompassing patient-specific details such as age, gender, cholesterol levels, blood pressure, heart rate, and indicators like diabetes, family history, smoking habits, obesity, and alcohol consumption. Additionally, lifestyle factors like exercise hours, dietary habits, stress levels, and sedentary hours are included. Medical aspects comprising previous heart problems, medication usage, and triglyceride levels are considered. Socioeconomic aspects such as income and geographical attributes like country, continent, and hemisphere are incorporated."
],
"metadata": {
"id": "nD8BIKMx-Hfc"
}
},
{
"cell_type": "markdown",
"source": [],
"metadata": {
"id": "EimkIzyj9p3w"
}
},
{
"cell_type": "markdown",
"source": [
"**Columns:**\n",
"\n",
"Patient ID - Unique identifier for each patient\n",
"\n",
"Age - Age of the patient\n",
"\n",
"Sex - Gender of the patient (Male/Female)\n",
"\n",
"Cholesterol - Cholesterol levels of the patient\n",
"\n",
"Blood Pressure - Blood pressure of the patient (systolic/diastolic)\n",
"\n",
"Heart Rate - Heart rate of the patient\n",
"\n",
"Diabetes - Whether the patient has diabetes (Yes/No)\n",
"\n",
"Family History - Family history of heart-related problems (1: Yes, 0: No)\n",
"\n",
"Smoking - Smoking status of the patient (1: Smoker, 0: Non-smoker)\n",
"\n",
"Obesity - Obesity status of the patient (1: Obese, 0: Not obese)\n",
"\n",
"Alcohol Consumption - Level of alcohol consumption by the patient (None/Light/Moderate/Heavy)\n",
"\n",
"Exercise Hours Per Week - Number of exercise hours per week\n",
"\n",
"Diet - Dietary habits of the patient (Healthy/Average/Unhealthy)\n",
"\n",
"Previous Heart Problems - Previous heart problems of the patient (1: Yes, 0: No)\n",
"\n",
"Medication Use - Medication usage by the patient (1: Yes, 0: No)\n",
"\n",
"Stress Level - Stress level reported by the patient (1-10)\n",
"\n",
"Sedentary Hours Per Day - Hours of sedentary activity per day\n",
"\n",
"Income - Income level of the patient\n",
"\n",
"BMI - Body Mass Index (BMI) of the patient\n",
"\n",
"Triglycerides - Triglyceride levels of the patient\n",
"\n",
"Physical Activity Days Per Week - Days of physical activity per week\n",
"\n",
"Sleep Hours Per Day - Hours of sleep per day\n",
"\n",
"Country - Country of the patient\n",
"\n",
"Continent - Continent where the patient resides\n",
"\n",
"Hemisphere - Hemisphere where the patient resides\n",
"\n",
"**Heart Attack Risk** (This is the target variable) - Presence of heart attack risk (1: Yes, 0: No)"
],
"metadata": {
"id": "tJHYH3-t-3NM"
}
},
{
"cell_type": "markdown",
"source": [
"This is a graded individual task (1 Grade)"
],
"metadata": {
"id": "ykqQ3n_DKl0O"
}
},
{
"cell_type": "markdown",
"source": [
"This notebook is a template and viwe only you can't save any of your code in it so, Use **Save a copy in drive** from File and start working on it to be able to save your changes."
],
"metadata": {
"id": "S365L2_yGjJF"
}
},
{
"cell_type": "markdown",
"source": [
"After you finish the task open the sharing options and make it any one with the link can view"
],
"metadata": {
"id": "vqjUBitnG9uV"
}
},
{
"cell_type": "markdown",
"source": [
"Copy the sharing link of the notebook and submit it in the google form in the task folder in google drive"
],
"metadata": {
"id": "stEGpqXfHK-m"
}
},
{
"cell_type": "markdown",
"source": [
"You can submit only once, if you submitted by mistake there is no option to resubmit agaian so be careful"
],
"metadata": {
"id": "BvJzP8MwdSlP"
}
},
{
"cell_type": "markdown",
"source": [
"Deadline is at **```29/10 Sunday 2 PM```**"
],
"metadata": {
"id": "Ae3mQV_MNQIk"
}
},
{
"cell_type": "code",
"source": [
"# install pandas-profilling\n",
"!pip install pandas-profiling"
],
"metadata": {
"id": "Ruzqg6W5GQ6F",
"colab": {
"base_uri": "https://localhost:8080/"
},
"outputId": "c63d6a6b-192c-49d5-efca-fdee6d650bd0"
},
"execution_count": 138,
"outputs": [
{
"output_type": "stream",
"name": "stdout",
"text": [
"Requirement already satisfied: pandas-profiling in /usr/local/lib/python3.10/dist-packages (3.6.6)\n",
"Requirement already satisfied: ydata-profiling in /usr/local/lib/python3.10/dist-packages (from pandas-profiling) (4.6.1)\n",
"Requirement already satisfied: scipy<1.12,>=1.4.1 in /usr/local/lib/python3.10/dist-packages (from ydata-profiling->pandas-profiling) (1.11.3)\n",
"Requirement already satisfied: pandas!=1.4.0,<2.1,>1.1 in /usr/local/lib/python3.10/dist-packages (from ydata-profiling->pandas-profiling) (1.5.3)\n",
"Requirement already satisfied: matplotlib<=3.7.3,>=3.2 in /usr/local/lib/python3.10/dist-packages (from ydata-profiling->pandas-profiling) (3.7.1)\n",
"Requirement already satisfied: pydantic>=2 in /usr/local/lib/python3.10/dist-packages (from ydata-profiling->pandas-profiling) (2.4.2)\n",
"Requirement already satisfied: PyYAML<6.1,>=5.0.0 in /usr/local/lib/python3.10/dist-packages (from ydata-profiling->pandas-profiling) (6.0.1)\n",
"Requirement already satisfied: jinja2<3.2,>=2.11.1 in /usr/local/lib/python3.10/dist-packages (from ydata-profiling->pandas-profiling) (3.1.2)\n",
"Requirement already satisfied: visions[type_image_path]==0.7.5 in /usr/local/lib/python3.10/dist-packages (from ydata-profiling->pandas-profiling) (0.7.5)\n",
"Requirement already satisfied: numpy<1.26,>=1.16.0 in /usr/local/lib/python3.10/dist-packages (from ydata-profiling->pandas-profiling) (1.23.5)\n",
"Requirement already satisfied: htmlmin==0.1.12 in /usr/local/lib/python3.10/dist-packages (from ydata-profiling->pandas-profiling) (0.1.12)\n",
"Requirement already satisfied: phik<0.13,>=0.11.1 in /usr/local/lib/python3.10/dist-packages (from ydata-profiling->pandas-profiling) (0.12.3)\n",
"Requirement already satisfied: requests<3,>=2.24.0 in /usr/local/lib/python3.10/dist-packages (from ydata-profiling->pandas-profiling) (2.31.0)\n",
"Requirement already satisfied: tqdm<5,>=4.48.2 in /usr/local/lib/python3.10/dist-packages (from ydata-profiling->pandas-profiling) (4.66.1)\n",
"Requirement already satisfied: seaborn<0.13,>=0.10.1 in /usr/local/lib/python3.10/dist-packages (from ydata-profiling->pandas-profiling) (0.12.2)\n",
"Requirement already satisfied: multimethod<2,>=1.4 in /usr/local/lib/python3.10/dist-packages (from ydata-profiling->pandas-profiling) (1.10)\n",
"Requirement already satisfied: statsmodels<1,>=0.13.2 in /usr/local/lib/python3.10/dist-packages (from ydata-profiling->pandas-profiling) (0.14.0)\n",
"Requirement already satisfied: typeguard<5,>=4.1.2 in /usr/local/lib/python3.10/dist-packages (from ydata-profiling->pandas-profiling) (4.1.5)\n",
"Requirement already satisfied: imagehash==4.3.1 in /usr/local/lib/python3.10/dist-packages (from ydata-profiling->pandas-profiling) (4.3.1)\n",
"Requirement already satisfied: wordcloud>=1.9.1 in /usr/local/lib/python3.10/dist-packages (from ydata-profiling->pandas-profiling) (1.9.2)\n",
"Requirement already satisfied: dacite>=1.8 in /usr/local/lib/python3.10/dist-packages (from ydata-profiling->pandas-profiling) (1.8.1)\n",
"Requirement already satisfied: numba<0.59.0,>=0.56.0 in /usr/local/lib/python3.10/dist-packages (from ydata-profiling->pandas-profiling) (0.56.4)\n",
"Requirement already satisfied: PyWavelets in /usr/local/lib/python3.10/dist-packages (from imagehash==4.3.1->ydata-profiling->pandas-profiling) (1.4.1)\n",
"Requirement already satisfied: pillow in /usr/local/lib/python3.10/dist-packages (from imagehash==4.3.1->ydata-profiling->pandas-profiling) (9.4.0)\n",
"Requirement already satisfied: attrs>=19.3.0 in /usr/local/lib/python3.10/dist-packages (from visions[type_image_path]==0.7.5->ydata-profiling->pandas-profiling) (23.1.0)\n",
"Requirement already satisfied: networkx>=2.4 in /usr/local/lib/python3.10/dist-packages (from visions[type_image_path]==0.7.5->ydata-profiling->pandas-profiling) (3.2)\n",
"Requirement already satisfied: tangled-up-in-unicode>=0.0.4 in /usr/local/lib/python3.10/dist-packages (from visions[type_image_path]==0.7.5->ydata-profiling->pandas-profiling) (0.2.0)\n",
"Requirement already satisfied: MarkupSafe>=2.0 in /usr/local/lib/python3.10/dist-packages (from jinja2<3.2,>=2.11.1->ydata-profiling->pandas-profiling) (2.1.3)\n",
"Requirement already satisfied: contourpy>=1.0.1 in /usr/local/lib/python3.10/dist-packages (from matplotlib<=3.7.3,>=3.2->ydata-profiling->pandas-profiling) (1.1.1)\n",
"Requirement already satisfied: cycler>=0.10 in /usr/local/lib/python3.10/dist-packages (from matplotlib<=3.7.3,>=3.2->ydata-profiling->pandas-profiling) (0.12.1)\n",
"Requirement already satisfied: fonttools>=4.22.0 in /usr/local/lib/python3.10/dist-packages (from matplotlib<=3.7.3,>=3.2->ydata-profiling->pandas-profiling) (4.43.1)\n",
"Requirement already satisfied: kiwisolver>=1.0.1 in /usr/local/lib/python3.10/dist-packages (from matplotlib<=3.7.3,>=3.2->ydata-profiling->pandas-profiling) (1.4.5)\n",
"Requirement already satisfied: packaging>=20.0 in /usr/local/lib/python3.10/dist-packages (from matplotlib<=3.7.3,>=3.2->ydata-profiling->pandas-profiling) (23.2)\n",
"Requirement already satisfied: pyparsing>=2.3.1 in /usr/local/lib/python3.10/dist-packages (from matplotlib<=3.7.3,>=3.2->ydata-profiling->pandas-profiling) (3.1.1)\n",
"Requirement already satisfied: python-dateutil>=2.7 in /usr/local/lib/python3.10/dist-packages (from matplotlib<=3.7.3,>=3.2->ydata-profiling->pandas-profiling) (2.8.2)\n",
"Requirement already satisfied: llvmlite<0.40,>=0.39.0dev0 in /usr/local/lib/python3.10/dist-packages (from numba<0.59.0,>=0.56.0->ydata-profiling->pandas-profiling) (0.39.1)\n",
"Requirement already satisfied: setuptools in /usr/local/lib/python3.10/dist-packages (from numba<0.59.0,>=0.56.0->ydata-profiling->pandas-profiling) (67.7.2)\n",
"Requirement already satisfied: pytz>=2020.1 in /usr/local/lib/python3.10/dist-packages (from pandas!=1.4.0,<2.1,>1.1->ydata-profiling->pandas-profiling) (2023.3.post1)\n",
"Requirement already satisfied: joblib>=0.14.1 in /usr/local/lib/python3.10/dist-packages (from phik<0.13,>=0.11.1->ydata-profiling->pandas-profiling) (1.3.2)\n",
"Requirement already satisfied: annotated-types>=0.4.0 in /usr/local/lib/python3.10/dist-packages (from pydantic>=2->ydata-profiling->pandas-profiling) (0.6.0)\n",
"Requirement already satisfied: pydantic-core==2.10.1 in /usr/local/lib/python3.10/dist-packages (from pydantic>=2->ydata-profiling->pandas-profiling) (2.10.1)\n",
"Requirement already satisfied: typing-extensions>=4.6.1 in /usr/local/lib/python3.10/dist-packages (from pydantic>=2->ydata-profiling->pandas-profiling) (4.8.0)\n",
"Requirement already satisfied: charset-normalizer<4,>=2 in /usr/local/lib/python3.10/dist-packages (from requests<3,>=2.24.0->ydata-profiling->pandas-profiling) (3.3.1)\n",
"Requirement already satisfied: idna<4,>=2.5 in /usr/local/lib/python3.10/dist-packages (from requests<3,>=2.24.0->ydata-profiling->pandas-profiling) (3.4)\n",
"Requirement already satisfied: urllib3<3,>=1.21.1 in /usr/local/lib/python3.10/dist-packages (from requests<3,>=2.24.0->ydata-profiling->pandas-profiling) (2.0.7)\n",
"Requirement already satisfied: certifi>=2017.4.17 in /usr/local/lib/python3.10/dist-packages (from requests<3,>=2.24.0->ydata-profiling->pandas-profiling) (2023.7.22)\n",
"Requirement already satisfied: patsy>=0.5.2 in /usr/local/lib/python3.10/dist-packages (from statsmodels<1,>=0.13.2->ydata-profiling->pandas-profiling) (0.5.3)\n",
"Requirement already satisfied: six in /usr/local/lib/python3.10/dist-packages (from patsy>=0.5.2->statsmodels<1,>=0.13.2->ydata-profiling->pandas-profiling) (1.16.0)\n"
]
}
]
},
{
"cell_type": "markdown",
"source": [
"**Important Note:** Restart the session **Runtime** of google colab after installing ```pandas-profiling``` then contniue"
],
"metadata": {
"id": "YALhRRI2Dzov"
}
},
{
"cell_type": "code",
"source": [
"# import the libraries that you will need here\n",
"import pandas as pd\n",
"import matplotlib.pyplot as plt\n",
"import ydata_profiling"
],
"metadata": {
"id": "RtJC5138M6X-"
},
"execution_count": 139,
"outputs": []
},
{
"cell_type": "code",
"source": [
"# Mount the drive and read the cvs file in a pandas dataframe\n",
"from google.colab import drive\n",
"drive.mount('/content/drive')"
],
"metadata": {
"id": "iZuowfoS_Qjk",
"colab": {
"base_uri": "https://localhost:8080/"
},
"outputId": "e132aa39-dbfe-4462-b77a-5b677fdf27bb"
},
"execution_count": 140,
"outputs": [
{
"output_type": "stream",
"name": "stdout",
"text": [
"Drive already mounted at /content/drive; to attempt to forcibly remount, call drive.mount(\"/content/drive\", force_remount=True).\n"
]
}
]
},
{
"cell_type": "code",
"source": [
"# Gnerate pandas profiling report to better understand and explore your data\n",
"data = pd.read_csv('/content/drive/MyDrive/LFD/Task1/نسخة من train.csv')\n",
"data"
],
"metadata": {
"id": "vkIO29Jy_X0r",
"colab": {
"base_uri": "https://localhost:8080/",
"height": 669
},
"outputId": "447f5333-5e9a-41f0-f84d-67ef395002f1"
},
"execution_count": 141,
"outputs": [
{
"output_type": "execute_result",
"data": {
"text/plain": [
" Patient ID Age Sex Cholesterol Blood Pressure Heart Rate \\\n",
"0 RDG0550 33 Male 200 129/90 48 \n",
"1 NMA3851 56 Female 262 159/105 46 \n",
"2 TUI5807 19 Female 140 161/109 54 \n",
"3 YYT5016 50 Female 163 120/62 53 \n",
"4 ZAC5937 89 Female 144 153/110 92 \n",
"... ... ... ... ... ... ... \n",
"7005 BCB2291 29 Female 267 104/105 87 \n",
"7006 KIG5207 83 Male 296 134/99 77 \n",
"7007 GCY1316 54 Male 120 134/84 103 \n",
"7008 RPK2629 42 Female 147 144/76 81 \n",
"7009 CWO3455 61 Male 176 172/60 56 \n",
"\n",
" Diabetes Family History Smoking Obesity ... \\\n",
"0 0 1 1 1 ... \n",
"1 1 0 1 0 ... \n",
"2 0 1 0 0 ... \n",
"3 0 1 1 1 ... \n",
"4 1 0 1 0 ... \n",
"... ... ... ... ... ... \n",
"7005 0 0 0 1 ... \n",
"7006 1 1 1 1 ... \n",
"7007 1 1 1 1 ... \n",
"7008 0 0 1 0 ... \n",
"7009 0 1 1 0 ... \n",
"\n",
" Sedentary Hours Per Day Income BMI Triglycerides \\\n",
"0 0.138443 184066 30.449815 63 \n",
"1 0.369552 211755 34.973685 333 \n",
"2 8.646334 252203 30.554246 537 \n",
"3 1.107884 121954 35.390265 591 \n",
"4 1.337570 180121 39.575483 145 \n",
"... ... ... ... ... \n",
"7005 6.806894 236184 27.521246 598 \n",
"7006 3.015648 264390 21.332449 465 \n",
"7007 4.825724 198358 37.465577 674 \n",
"7008 6.546390 202828 28.605789 623 \n",
"7009 6.651328 25823 22.057046 224 \n",
"\n",
" Physical Activity Days Per Week Sleep Hours Per Day Country \\\n",
"0 6 7 Argentina \n",
"1 7 8 Nigeria \n",
"2 2 10 Thailand \n",
"3 0 9 Spain \n",
"4 2 5 Germany \n",
"... ... ... ... \n",
"7005 4 5 France \n",
"7006 4 4 United Kingdom \n",
"7007 6 9 Colombia \n",
"7008 7 10 Spain \n",
"7009 7 10 India \n",
"\n",
" Continent Hemisphere Heart Attack Risk \n",
"0 South America Southern Hemisphere 1 \n",
"1 Africa Northern Hemisphere 1 \n",
"2 Asia Northern Hemisphere 0 \n",
"3 Europe Southern Hemisphere 1 \n",
"4 Europe Northern Hemisphere 1 \n",
"... ... ... ... \n",
"7005 Europe Northern Hemisphere 0 \n",
"7006 Europe Northern Hemisphere 0 \n",
"7007 South America Northern Hemisphere 0 \n",
"7008 Europe Southern Hemisphere 1 \n",
"7009 Asia Northern Hemisphere 0 \n",
"\n",
"[7010 rows x 26 columns]"
],
"text/html": [
"\n",
" <div id=\"df-1884f0ce-3cc0-48ff-a24e-8193dfc89109\" class=\"colab-df-container\">\n",
" <div>\n",
"<style scoped>\n",
" .dataframe tbody tr th:only-of-type {\n",
" vertical-align: middle;\n",
" }\n",
"\n",
" .dataframe tbody tr th {\n",
" vertical-align: top;\n",
" }\n",
"\n",
" .dataframe thead th {\n",
" text-align: right;\n",
" }\n",
"</style>\n",
"<table border=\"1\" class=\"dataframe\">\n",
" <thead>\n",
" <tr style=\"text-align: right;\">\n",
" <th></th>\n",
" <th>Patient ID</th>\n",
" <th>Age</th>\n",
" <th>Sex</th>\n",
" <th>Cholesterol</th>\n",
" <th>Blood Pressure</th>\n",
" <th>Heart Rate</th>\n",
" <th>Diabetes</th>\n",
" <th>Family History</th>\n",
" <th>Smoking</th>\n",
" <th>Obesity</th>\n",
" <th>...</th>\n",
" <th>Sedentary Hours Per Day</th>\n",
" <th>Income</th>\n",
" <th>BMI</th>\n",
" <th>Triglycerides</th>\n",
" <th>Physical Activity Days Per Week</th>\n",
" <th>Sleep Hours Per Day</th>\n",
" <th>Country</th>\n",
" <th>Continent</th>\n",
" <th>Hemisphere</th>\n",
" <th>Heart Attack Risk</th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>0</th>\n",
" <td>RDG0550</td>\n",
" <td>33</td>\n",
" <td>Male</td>\n",
" <td>200</td>\n",
" <td>129/90</td>\n",
" <td>48</td>\n",
" <td>0</td>\n",
" <td>1</td>\n",
" <td>1</td>\n",
" <td>1</td>\n",
" <td>...</td>\n",
" <td>0.138443</td>\n",
" <td>184066</td>\n",
" <td>30.449815</td>\n",
" <td>63</td>\n",
" <td>6</td>\n",
" <td>7</td>\n",
" <td>Argentina</td>\n",
" <td>South America</td>\n",
" <td>Southern Hemisphere</td>\n",
" <td>1</td>\n",
" </tr>\n",
" <tr>\n",
" <th>1</th>\n",
" <td>NMA3851</td>\n",
" <td>56</td>\n",
" <td>Female</td>\n",
" <td>262</td>\n",
" <td>159/105</td>\n",
" <td>46</td>\n",
" <td>1</td>\n",
" <td>0</td>\n",
" <td>1</td>\n",
" <td>0</td>\n",
" <td>...</td>\n",
" <td>0.369552</td>\n",
" <td>211755</td>\n",
" <td>34.973685</td>\n",
" <td>333</td>\n",
" <td>7</td>\n",
" <td>8</td>\n",
" <td>Nigeria</td>\n",
" <td>Africa</td>\n",
" <td>Northern Hemisphere</td>\n",
" <td>1</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2</th>\n",
" <td>TUI5807</td>\n",
" <td>19</td>\n",
" <td>Female</td>\n",
" <td>140</td>\n",
" <td>161/109</td>\n",
" <td>54</td>\n",
" <td>0</td>\n",
" <td>1</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>...</td>\n",
" <td>8.646334</td>\n",
" <td>252203</td>\n",
" <td>30.554246</td>\n",
" <td>537</td>\n",
" <td>2</td>\n",
" <td>10</td>\n",
" <td>Thailand</td>\n",
" <td>Asia</td>\n",
" <td>Northern Hemisphere</td>\n",
" <td>0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>3</th>\n",
" <td>YYT5016</td>\n",
" <td>50</td>\n",
" <td>Female</td>\n",
" <td>163</td>\n",
" <td>120/62</td>\n",
" <td>53</td>\n",
" <td>0</td>\n",
" <td>1</td>\n",
" <td>1</td>\n",
" <td>1</td>\n",
" <td>...</td>\n",
" <td>1.107884</td>\n",
" <td>121954</td>\n",
" <td>35.390265</td>\n",
" <td>591</td>\n",
" <td>0</td>\n",
" <td>9</td>\n",
" <td>Spain</td>\n",
" <td>Europe</td>\n",
" <td>Southern Hemisphere</td>\n",
" <td>1</td>\n",
" </tr>\n",
" <tr>\n",
" <th>4</th>\n",
" <td>ZAC5937</td>\n",
" <td>89</td>\n",
" <td>Female</td>\n",
" <td>144</td>\n",
" <td>153/110</td>\n",
" <td>92</td>\n",
" <td>1</td>\n",
" <td>0</td>\n",
" <td>1</td>\n",
" <td>0</td>\n",
" <td>...</td>\n",
" <td>1.337570</td>\n",
" <td>180121</td>\n",
" <td>39.575483</td>\n",
" <td>145</td>\n",
" <td>2</td>\n",
" <td>5</td>\n",
" <td>Germany</td>\n",
" <td>Europe</td>\n",
" <td>Northern Hemisphere</td>\n",
" <td>1</td>\n",
" </tr>\n",
" <tr>\n",
" <th>...</th>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" </tr>\n",
" <tr>\n",
" <th>7005</th>\n",
" <td>BCB2291</td>\n",
" <td>29</td>\n",
" <td>Female</td>\n",
" <td>267</td>\n",
" <td>104/105</td>\n",
" <td>87</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>1</td>\n",
" <td>...</td>\n",
" <td>6.806894</td>\n",
" <td>236184</td>\n",
" <td>27.521246</td>\n",
" <td>598</td>\n",
" <td>4</td>\n",
" <td>5</td>\n",
" <td>France</td>\n",
" <td>Europe</td>\n",
" <td>Northern Hemisphere</td>\n",
" <td>0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>7006</th>\n",
" <td>KIG5207</td>\n",
" <td>83</td>\n",
" <td>Male</td>\n",
" <td>296</td>\n",
" <td>134/99</td>\n",
" <td>77</td>\n",
" <td>1</td>\n",
" <td>1</td>\n",
" <td>1</td>\n",
" <td>1</td>\n",
" <td>...</td>\n",
" <td>3.015648</td>\n",
" <td>264390</td>\n",
" <td>21.332449</td>\n",
" <td>465</td>\n",
" <td>4</td>\n",
" <td>4</td>\n",
" <td>United Kingdom</td>\n",
" <td>Europe</td>\n",
" <td>Northern Hemisphere</td>\n",
" <td>0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>7007</th>\n",
" <td>GCY1316</td>\n",
" <td>54</td>\n",
" <td>Male</td>\n",
" <td>120</td>\n",
" <td>134/84</td>\n",
" <td>103</td>\n",
" <td>1</td>\n",
" <td>1</td>\n",
" <td>1</td>\n",
" <td>1</td>\n",
" <td>...</td>\n",
" <td>4.825724</td>\n",
" <td>198358</td>\n",
" <td>37.465577</td>\n",
" <td>674</td>\n",
" <td>6</td>\n",
" <td>9</td>\n",
" <td>Colombia</td>\n",
" <td>South America</td>\n",
" <td>Northern Hemisphere</td>\n",
" <td>0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>7008</th>\n",
" <td>RPK2629</td>\n",
" <td>42</td>\n",
" <td>Female</td>\n",
" <td>147</td>\n",
" <td>144/76</td>\n",
" <td>81</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>1</td>\n",
" <td>0</td>\n",
" <td>...</td>\n",
" <td>6.546390</td>\n",
" <td>202828</td>\n",
" <td>28.605789</td>\n",
" <td>623</td>\n",
" <td>7</td>\n",
" <td>10</td>\n",
" <td>Spain</td>\n",
" <td>Europe</td>\n",
" <td>Southern Hemisphere</td>\n",
" <td>1</td>\n",
" </tr>\n",
" <tr>\n",
" <th>7009</th>\n",
" <td>CWO3455</td>\n",
" <td>61</td>\n",
" <td>Male</td>\n",
" <td>176</td>\n",
" <td>172/60</td>\n",
" <td>56</td>\n",
" <td>0</td>\n",
" <td>1</td>\n",
" <td>1</td>\n",
" <td>0</td>\n",
" <td>...</td>\n",
" <td>6.651328</td>\n",
" <td>25823</td>\n",
" <td>22.057046</td>\n",
" <td>224</td>\n",
" <td>7</td>\n",
" <td>10</td>\n",
" <td>India</td>\n",
" <td>Asia</td>\n",
" <td>Northern Hemisphere</td>\n",
" <td>0</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"<p>7010 rows × 26 columns</p>\n",
"</div>\n",
" <div class=\"colab-df-buttons\">\n",
"\n",
" <div class=\"colab-df-container\">\n",
" <button class=\"colab-df-convert\" onclick=\"convertToInteractive('df-1884f0ce-3cc0-48ff-a24e-8193dfc89109')\"\n",
" title=\"Convert this dataframe to an interactive table.\"\n",
" style=\"display:none;\">\n",
"\n",
" <svg xmlns=\"http://www.w3.org/2000/svg\" height=\"24px\" viewBox=\"0 -960 960 960\">\n",
" <path d=\"M120-120v-720h720v720H120Zm60-500h600v-160H180v160Zm220 220h160v-160H400v160Zm0 220h160v-160H400v160ZM180-400h160v-160H180v160Zm440 0h160v-160H620v160ZM180-180h160v-160H180v160Zm440 0h160v-160H620v160Z\"/>\n",
" </svg>\n",
" </button>\n",
"\n",
" <style>\n",
" .colab-df-container {\n",
" display:flex;\n",
" gap: 12px;\n",
" }\n",
"\n",
" .colab-df-convert {\n",
" background-color: #E8F0FE;\n",
" border: none;\n",
" border-radius: 50%;\n",
" cursor: pointer;\n",
" display: none;\n",
" fill: #1967D2;\n",
" height: 32px;\n",
" padding: 0 0 0 0;\n",
" width: 32px;\n",
" }\n",
"\n",
" .colab-df-convert:hover {\n",
" background-color: #E2EBFA;\n",
" box-shadow: 0px 1px 2px rgba(60, 64, 67, 0.3), 0px 1px 3px 1px rgba(60, 64, 67, 0.15);\n",
" fill: #174EA6;\n",
" }\n",
"\n",
" .colab-df-buttons div {\n",
" margin-bottom: 4px;\n",
" }\n",
"\n",
" [theme=dark] .colab-df-convert {\n",
" background-color: #3B4455;\n",
" fill: #D2E3FC;\n",
" }\n",
"\n",
" [theme=dark] .colab-df-convert:hover {\n",
" background-color: #434B5C;\n",
" box-shadow: 0px 1px 3px 1px rgba(0, 0, 0, 0.15);\n",
" filter: drop-shadow(0px 1px 2px rgba(0, 0, 0, 0.3));\n",
" fill: #FFFFFF;\n",
" }\n",
" </style>\n",
"\n",
" <script>\n",
" const buttonEl =\n",
" document.querySelector('#df-1884f0ce-3cc0-48ff-a24e-8193dfc89109 button.colab-df-convert');\n",
" buttonEl.style.display =\n",
" google.colab.kernel.accessAllowed ? 'block' : 'none';\n",
"\n",
" async function convertToInteractive(key) {\n",
" const element = document.querySelector('#df-1884f0ce-3cc0-48ff-a24e-8193dfc89109');\n",
" const dataTable =\n",
" await google.colab.kernel.invokeFunction('convertToInteractive',\n",
" [key], {});\n",
" if (!dataTable) return;\n",
"\n",
" const docLinkHtml = 'Like what you see? Visit the ' +\n",
" '<a target=\"_blank\" href=https://colab.research.google.com/notebooks/data_table.ipynb>data table notebook</a>'\n",
" + ' to learn more about interactive tables.';\n",
" element.innerHTML = '';\n",
" dataTable['output_type'] = 'display_data';\n",
" await google.colab.output.renderOutput(dataTable, element);\n",
" const docLink = document.createElement('div');\n",
" docLink.innerHTML = docLinkHtml;\n",
" element.appendChild(docLink);\n",
" }\n",
" </script>\n",
" </div>\n",
"\n",
"\n",
"<div id=\"df-853f2ad0-e2cd-4784-ba88-50e21fbe1e5d\">\n",
" <button class=\"colab-df-quickchart\" onclick=\"quickchart('df-853f2ad0-e2cd-4784-ba88-50e21fbe1e5d')\"\n",
" title=\"Suggest charts.\"\n",
" style=\"display:none;\">\n",
"\n",
"<svg xmlns=\"http://www.w3.org/2000/svg\" height=\"24px\"viewBox=\"0 0 24 24\"\n",
" width=\"24px\">\n",
" <g>\n",
" <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",
" </g>\n",
"</svg>\n",
" </button>\n",
"\n",
"<style>\n",
" .colab-df-quickchart {\n",
" --bg-color: #E8F0FE;\n",
" --fill-color: #1967D2;\n",
" --hover-bg-color: #E2EBFA;\n",
" --hover-fill-color: #174EA6;\n",
" --disabled-fill-color: #AAA;\n",
" --disabled-bg-color: #DDD;\n",
" }\n",
"\n",
" [theme=dark] .colab-df-quickchart {\n",
" --bg-color: #3B4455;\n",
" --fill-color: #D2E3FC;\n",
" --hover-bg-color: #434B5C;\n",
" --hover-fill-color: #FFFFFF;\n",
" --disabled-bg-color: #3B4455;\n",
" --disabled-fill-color: #666;\n",
" }\n",
"\n",
" .colab-df-quickchart {\n",
" background-color: var(--bg-color);\n",
" border: none;\n",
" border-radius: 50%;\n",
" cursor: pointer;\n",
" display: none;\n",
" fill: var(--fill-color);\n",
" height: 32px;\n",
" padding: 0;\n",
" width: 32px;\n",
" }\n",
"\n",
" .colab-df-quickchart:hover {\n",
" background-color: var(--hover-bg-color);\n",
" box-shadow: 0 1px 2px rgba(60, 64, 67, 0.3), 0 1px 3px 1px rgba(60, 64, 67, 0.15);\n",
" fill: var(--button-hover-fill-color);\n",
" }\n",
"\n",
" .colab-df-quickchart-complete:disabled,\n",
" .colab-df-quickchart-complete:disabled:hover {\n",
" background-color: var(--disabled-bg-color);\n",
" fill: var(--disabled-fill-color);\n",
" box-shadow: none;\n",
" }\n",
"\n",
" .colab-df-spinner {\n",
" border: 2px solid var(--fill-color);\n",
" border-color: transparent;\n",
" border-bottom-color: var(--fill-color);\n",
" animation:\n",
" spin 1s steps(1) infinite;\n",
" }\n",
"\n",
" @keyframes spin {\n",
" 0% {\n",
" border-color: transparent;\n",
" border-bottom-color: var(--fill-color);\n",
" border-left-color: var(--fill-color);\n",
" }\n",
" 20% {\n",
" border-color: transparent;\n",
" border-left-color: var(--fill-color);\n",
" border-top-color: var(--fill-color);\n",
" }\n",
" 30% {\n",
" border-color: transparent;\n",
" border-left-color: var(--fill-color);\n",
" border-top-color: var(--fill-color);\n",
" border-right-color: var(--fill-color);\n",
" }\n",
" 40% {\n",
" border-color: transparent;\n",
" border-right-color: var(--fill-color);\n",
" border-top-color: var(--fill-color);\n",
" }\n",
" 60% {\n",
" border-color: transparent;\n",
" border-right-color: var(--fill-color);\n",
" }\n",
" 80% {\n",
" border-color: transparent;\n",
" border-right-color: var(--fill-color);\n",
" border-bottom-color: var(--fill-color);\n",
" }\n",
" 90% {\n",
" border-color: transparent;\n",
" border-bottom-color: var(--fill-color);\n",
" }\n",
" }\n",
"</style>\n",
"\n",
" <script>\n",
" async function quickchart(key) {\n",
" const quickchartButtonEl =\n",
" document.querySelector('#' + key + ' button');\n",
" quickchartButtonEl.disabled = true; // To prevent multiple clicks.\n",
" quickchartButtonEl.classList.add('colab-df-spinner');\n",
" try {\n",
" const charts = await google.colab.kernel.invokeFunction(\n",
" 'suggestCharts', [key], {});\n",
" } catch (error) {\n",
" console.error('Error during call to suggestCharts:', error);\n",
" }\n",
" quickchartButtonEl.classList.remove('colab-df-spinner');\n",
" quickchartButtonEl.classList.add('colab-df-quickchart-complete');\n",
" }\n",
" (() => {\n",
" let quickchartButtonEl =\n",
" document.querySelector('#df-853f2ad0-e2cd-4784-ba88-50e21fbe1e5d button');\n",
" quickchartButtonEl.style.display =\n",
" google.colab.kernel.accessAllowed ? 'block' : 'none';\n",
" })();\n",
" </script>\n",
"</div>\n",
" </div>\n",
" </div>\n"
]
},
"metadata": {},
"execution_count": 141
}
]
},
{
"cell_type": "code",
"source": [
"# choose one variable to drop and explain why in a text cell\n",
"data.drop('Patient ID', axis=1,inplace=True)\n"
],
"metadata": {
"id": "2FqbxtpCEbw-"
},
"execution_count": 142,
"outputs": []
},
{
"cell_type": "markdown",
"source": [
"The \"Patient ID\" is a unique identifier for each patient. It doesn't provide any meaningful information related to heart attack risk. It's typically used for tracking and database management, but it doesn't offer any insights into the factors affecting heart attack risk."
],
"metadata": {
"id": "eKPXyIZjQPjn"
}
},
{
"cell_type": "code",
"source": [
"# answer with yes or no, dose the data contain missing values ?\n",
"if (data.isnull().sum().sum()>0) :\n",
" print('yes')\n",
"else :\n",
" print('no')"
],
"metadata": {
"id": "xFOkIfqeFwdl",
"colab": {
"base_uri": "https://localhost:8080/"
},
"outputId": "d353768e-e040-4dfd-f2d3-3d8178bd052d"
},
"execution_count": 143,
"outputs": [
{
"output_type": "stream",
"name": "stdout",
"text": [
"no\n"
]
}
]
},
{
"cell_type": "code",
"source": [
"# drop any row from tha dataframe if its age is higher than 80\n",
"data.drop(data[data['Age'] > 80].index, inplace=True)"
],
"metadata": {
"id": "kqABLAUVF6H9"
},
"execution_count": 144,
"outputs": []
},
{
"cell_type": "code",
"source": [
"# create new feature driven from the variables in the data\n",
"\n",
"def determine_cardio_risk(row):\n",
" if (\n",
" row['Cholesterol'] > 200 or\n",
"\n",
" row['Heart Rate'] > 100 or\n",
" row['Diabetes'] == 'Yes' or\n",
" row['Family History'] == 1 or\n",
" row['Smoking'] == 1 or\n",
" row['Obesity'] == 1\n",
" ):\n",
" return 1 # High risk\n",
" else:\n",
" return 0 # Low risk\n",
"\n",
"# Apply the function to create the new feature 'Cardio Risk'\n",
"data['Cardio Risk'] = data.apply(determine_cardio_risk, axis=1)\n",
"\n",
"data"
],
"metadata": {
"id": "HAseyVdQMt99",
"colab": {
"base_uri": "https://localhost:8080/",
"height": 669
},
"outputId": "beddea4d-2850-406f-f81e-988403de8032"
},
"execution_count": 145,
"outputs": [
{
"output_type": "execute_result",
"data": {