|
a |
|
b/MOA/Pressure.py |
|
|
1 |
import numpy as np |
|
|
2 |
import pandas as panda |
|
|
3 |
import matplotlib.pyplot as plt |
|
|
4 |
from scipy.stats import norm |
|
|
5 |
import statistics |
|
|
6 |
|
|
|
7 |
|
|
|
8 |
# Consider Gluc Values > 1 Is A Diabetes |
|
|
9 |
|
|
|
10 |
db = panda.read_csv('cardio_train.csv') |
|
|
11 |
|
|
|
12 |
UpPressure = db.loc[db.cardio == 1].ap_hi |
|
|
13 |
DownPressure = db.loc[db.cardio == 1].ap_lo |
|
|
14 |
|
|
|
15 |
UpPressureQ25,UpPressureQ75 = np.percentile(UpPressure,[25,75]) |
|
|
16 |
|
|
|
17 |
IQR = UpPressureQ75 - UpPressureQ25 |
|
|
18 |
|
|
|
19 |
|
|
|
20 |
plt.boxplot(UpPressure) |
|
|
21 |
plt.title("Before Cleaning") |
|
|
22 |
plt.show() |
|
|
23 |
|
|
|
24 |
# Cleaning Data |
|
|
25 |
UpPressure = UpPressure.loc[UpPressure >= (UpPressureQ25 - 1.5 * IQR)].loc[UpPressure <= (UpPressureQ75 + 1.5 * IQR)] |
|
|
26 |
|
|
|
27 |
|
|
|
28 |
plt.boxplot(UpPressure) |
|
|
29 |
plt.title("After Cleaning") |
|
|
30 |
plt.show() |
|
|
31 |
|
|
|
32 |
UpPressureMean = UpPressure.mean() |
|
|
33 |
UpPressureMedian = UpPressure.median() |
|
|
34 |
UpPressureMode = UpPressure.mode() |
|
|
35 |
UpPressureSD = UpPressure.std() |
|
|
36 |
|
|
|
37 |
|
|
|
38 |
print("Systolic blood pressure Mean = " + str(UpPressureMean)) |
|
|
39 |
print("Systolic blood pressure Median = " + str(UpPressureMedian)) |
|
|
40 |
# print("Systolic blood pressure Mode = " + str(UpPressureMode)) |
|
|
41 |
print("Systolic blood pressure Standard Deviation = " + str(UpPressureSD)) |
|
|
42 |
|
|
|
43 |
# Hypothesis: Abnormal Systolic blood Pressure is a sign of heart disease |
|
|
44 |
# Check If Probabilty Of Having Both Normal blood pressure and heart disease is greater than having abnormal blood pressure |
|
|
45 |
|
|
|
46 |
|
|
|
47 |
NormalPressure = UpPressure.loc[UpPressure >= 120].loc[UpPressure < 130] |
|
|
48 |
UpLowPressure = UpPressure.loc[UpPressure < 120] |
|
|
49 |
UpHighPressure = UpPressure.loc[UpPressure >= 130] |
|
|
50 |
|
|
|
51 |
|
|
|
52 |
PNormalPressure = (NormalPressure.count()) * 100 / UpPressure.count() |
|
|
53 |
PabNormalPressure = (UpLowPressure.count() + UpHighPressure.count()) * 100 / UpPressure.count() |
|
|
54 |
|
|
|
55 |
print("Propability of Of Having Both Normal blood pressure and heart disease = " + str(PNormalPressure)) |
|
|
56 |
print("Propability of Of Having Both Abnormal blood pressure and heart disease = " + str(PabNormalPressure)) |
|
|
57 |
|
|
|
58 |
plt.pie([PNormalPressure,PabNormalPressure],labels= ["Normal Pressure", "Abnormal Pressure"]) |
|
|
59 |
plt.title("Probability of having") |
|
|
60 |
plt.show() |
|
|
61 |
|
|
|
62 |
#===================================================================================================== |
|
|
63 |
|
|
|
64 |
# DownPressureQ25,DownPressureQ75 = np.percentile(DownPressure,[25,75]) |
|
|
65 |
# IQR = DownPressureQ75 - DownPressureQ25 |
|
|
66 |
|
|
|
67 |
# plt.boxplot(UpPressure) |
|
|
68 |
# plt.title("Before Cleaning") |
|
|
69 |
# plt.show() |
|
|
70 |
|
|
|
71 |
# Cleaning Data |
|
|
72 |
# DownPressure = DownPressure.loc[DownPressure >= (DownPressureQ25 - 1.5 * IQR)].loc[DownPressure <= (DownPressureQ75 + 1.5 * IQR)] |
|
|
73 |
|
|
|
74 |
# DownPressureMean = DownPressure.mean() |
|
|
75 |
# DownPressureMedian = DownPressure.median() |
|
|
76 |
# DownPressureMode = DownPressure.mode() |
|
|
77 |
# DownPressureSD = DownPressure.std() |
|
|
78 |
|
|
|
79 |
# # plt.boxplot(UpPressure) |
|
|
80 |
# # plt.title("After Cleaning") |
|
|
81 |
# # plt.show() |
|
|
82 |
|
|
|
83 |
|
|
|
84 |
# NormalPressure = UpPressure.loc[UpPressure] |
|
|
85 |
|
|
|
86 |
|