Adrian8a commited on
Commit
32788dd
1 Parent(s): 17addcb

Upload 11 files

Browse files
Files changed (11) hide show
  1. X_pca.data +0 -0
  2. app.py +133 -0
  3. dime.fig +0 -0
  4. forest.model +3 -0
  5. kmeans.model +3 -0
  6. log_reg.model +3 -0
  7. nb.model +3 -0
  8. pca.dim +0 -0
  9. stdscaler.model +3 -0
  10. tree.model +3 -0
  11. y.data +0 -0
X_pca.data ADDED
Binary file (5.02 kB). View file
 
app.py ADDED
@@ -0,0 +1,133 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from statistics import mode
2
+ from cProfile import label
3
+ from joblib import load
4
+
5
+ import matplotlib.pyplot as plt
6
+ import gradio as gr
7
+ import numpy as np
8
+
9
+ def getdata(Age,Sex,CP,Trtbps,Chol,Fbs,Restecg,Thalachh,Oldpeak,Slp,Caa,Thall,Exng):
10
+
11
+ if Sex == "Male":
12
+ Sex = 1
13
+ else:
14
+ Sex = 0
15
+
16
+ if CP == "Typical Angina":
17
+ CP = 0
18
+ elif CP == "Atypical Angina":
19
+ CP = 1
20
+ elif CP == "Non-anginal Pain":
21
+ CP = 2
22
+ else:
23
+ CP = 3
24
+
25
+ if Fbs == "True":
26
+ Fbs = 1
27
+ else:
28
+ Fbs = 0
29
+
30
+ if Restecg == "Normal":
31
+ Restecg = 0
32
+ elif Restecg == "ST-T wave normality":
33
+ Restecg = 1
34
+ else:
35
+ Restecg = 2
36
+
37
+ if Exng == "Yes":
38
+ Exng = 1
39
+ else:
40
+ Exng = 0
41
+
42
+ a = [Age,Sex,CP,Trtbps,Chol,Fbs,Restecg,Thalachh,Exng,Oldpeak,Slp,Caa,Thall]
43
+ arr = np.array([a])
44
+
45
+ return arr
46
+
47
+ def getfig(X_test):
48
+ X_pca = load('X_pca.data')
49
+ y = load('y.data')
50
+
51
+ pca = load('pca.dim')
52
+ u_pca = pca.transform(X_test)
53
+
54
+ fig = plt.figure(figsize=(5,4))
55
+
56
+ plt.scatter(X_pca[:, 0], X_pca[:, 1], c = y, cmap = plt.cm.Spectral, s = 10)
57
+ plt.scatter(u_pca[:, 0], u_pca[:, 1], c = 'g', cmap = plt.cm.Spectral, s = 40)
58
+ plt.title(f"PCA, Exp. Variance: {np.round(np.sum(pca.explained_variance_ratio_), 4)}")
59
+ plt.xlabel("PC 1")
60
+ plt.ylabel("PC 2")
61
+
62
+ return fig
63
+
64
+ def greet(Age,Sex,CP,Trtbps,Chol,Fbs,Restecg,Thalachh,Oldpeak,Slp,Caa,Thall,Exng):
65
+
66
+ X_test = getdata(Age,Sex,CP,Trtbps,Chol,Fbs,Restecg,Thalachh,Oldpeak,Slp,Caa,Thall,Exng)
67
+
68
+ scaler = load('stdscaler.model')
69
+ x_std = scaler.transform(X_test)
70
+
71
+ log_reg = load('log_reg.model')
72
+ y_lr = log_reg.predict(x_std)
73
+
74
+ kmeans = load('kmeans.model')
75
+ y_km = kmeans.predict(x_std)
76
+
77
+ tree = load('tree.model')
78
+ y_tree = tree.predict(x_std)
79
+
80
+ nb = load('nb.model')
81
+ y_bayes = nb.predict(X_test)
82
+
83
+ forest = load('forest.model')
84
+ y_forest = forest.predict(X_test)
85
+
86
+ r = [y_lr[0], y_km[0], y_tree[0], y_bayes[0], y_forest[0]]
87
+
88
+ f = mode(r)
89
+
90
+ if f == 0:
91
+ x = "You have less chance of heart attack"
92
+ else:
93
+ x = "You have more chance of heart attack"
94
+
95
+ fig = load('dime.fig')
96
+
97
+ fig2 = getfig(X_test)
98
+
99
+ return x, fig, fig2
100
+
101
+
102
+ interface = gr.Interface(
103
+ title = "HeartAttack prediction - UMG <br> Project Coeur ❤",
104
+ description = "<h3>The idea is to classify between 0 = less chance of heart attack and 1 = more chance of heart attack, according to the data provided by the user.</h3>"+
105
+ "<b>Models:</b> Logistic Regression, K-means, Decision Trees, Naive Bayes and Random Forest"+
106
+ "<br><b>Metrics:</b> Accuracy: 0.82, Precision: 0.775, Recall: 0.939, F1 Score: 0.849 <br> <br><b>Please provide the requested data:</b>",
107
+ article='Step-by-step on GitHub <a href="https://github.com/Adrian8aS/Machine-Learning-App-Gradio/blob/21246d9ba87859e9068369b89d48b4c6ee13dfe5/Proyecto%20integrador.ipynb"> notebook </a> '+
108
+ '<br>Dashboard of our train data <a href="https://1drv.ms/x/s!At7E16oDTBiKktUagvJHHpF5CCoITA?e=fOLjUq"> here! </a> '+
109
+ '<br>Privacy Policy <a href="https://raw.githubusercontent.com/rulasvrdz/DataMining/main/Texto.txt"> here! </a> '+
110
+ "<br><br> ~ Project Coeur",
111
+ allow_flagging = "never",
112
+ fn = greet,
113
+ inputs = [
114
+ gr.Number(label="Age of the patient"),
115
+ gr.Radio(["Male", "Female"], label="Sex of the patient"),
116
+ gr.Radio(["Typical Angina", "Atypical Angina", "Non-anginal Pain", "Asymptomatic"], label="Chest pain type"),
117
+ gr.Number(label="Resting blood pressure (in mm Hg)"),
118
+ gr.Number(label="Cholestoral in mg/dl fetched via BMI sensor"),
119
+ gr.Radio(["True", "False"], label="Fasting blood sugar > 120 mg/dl"),
120
+ gr.Radio(["Normal", "ST-T wave normality", "Left ventricular hypertrophy"], label="Resting electrocardiographic results"),
121
+ gr.Number(label="Maximum heart rate achieved"),
122
+ gr.Number(label="Previous peak"),
123
+ gr.Radio([0, 1, 2], label="Slope"),
124
+ gr.Radio([0, 1, 2, 3, 4], label="Number of major vessels"),
125
+ gr.Radio([0, 1, 2, 3], label="Thalium Stress Test result"),
126
+ gr.Radio(["Yes", "No"], label="Exercise induced angina")
127
+ ],
128
+ outputs = [gr.Text(label="Prediction"), 'plot', 'plot'],
129
+ examples = [[41,"Female","Typical Angina",130,204,"False","Normal",172,1.4,2,0,2,"No"],
130
+ [45,"Male","Non-anginal Pain",110,264,"False","ST-T wave normality",132,0.2,1,0,3,"No"]]
131
+ )
132
+
133
+ interface.launch(share = False)
dime.fig ADDED
Binary file (424 kB). View file
 
forest.model ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:3da56481146795354070b14c02880418a191267b056eec5414347134757d79b1
3
+ size 633758
kmeans.model ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:4f9d8cdebc8c83b6946b475004332c9413f97c45eb3c09c7978cd3e10aff1834
3
+ size 1831
log_reg.model ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:49d5c1cded04e1f5d3c61a6363b5333bfd28a2888fbce2f4115c4b47e3aa570b
3
+ size 886
nb.model ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:69ad050f1449fcb6aa41f6187d977ad21adac71073006b8697d9ac219917027f
3
+ size 1100
pca.dim ADDED
Binary file (1.59 kB). View file
 
stdscaler.model ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:f1460e2c8a2c392f8b31f63ba3665c7857e5c0436eefa1c25f2dd9bb44e9beb3
3
+ size 1287
tree.model ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:ee68b46534b043452768d8f16f33082b6af2a9dd9f99601b230add682ac4b5de
3
+ size 4220
y.data ADDED
Binary file (10.4 kB). View file