Upload 4 files
Browse files- app.py +87 -0
- death_pred.pkl +3 -0
- h8dsft_P1G3_AlselloDM.ipynb +0 -0
- requirements.txt +4 -0
app.py
ADDED
@@ -0,0 +1,87 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import streamlit as st
|
2 |
+
import pandas as pd
|
3 |
+
import pickle
|
4 |
+
|
5 |
+
|
6 |
+
# Title
|
7 |
+
st.write("""
|
8 |
+
# DEATH PREDICTION APP
|
9 |
+
|
10 |
+
This app predicts the likelihood of a patient's **Death** .
|
11 |
+
|
12 |
+
""")
|
13 |
+
|
14 |
+
@st.cache_data
|
15 |
+
def fetch_data():
|
16 |
+
df = pd.read_csv('h8dsft_P1G3_AlselloDM.csv')
|
17 |
+
return df
|
18 |
+
|
19 |
+
df = fetch_data()
|
20 |
+
|
21 |
+
st.sidebar.title("Patient's Medical Records")
|
22 |
+
st.sidebar.write('Please enter the condition here')
|
23 |
+
st.sidebar.title("Prediction Form📋")
|
24 |
+
|
25 |
+
def user_input_features():
|
26 |
+
# Age of the patient
|
27 |
+
age = st.sidebar.number_input("Age of the patient", 1,100)
|
28 |
+
# Decrease of red blood cells or hemoglobin
|
29 |
+
anaemia = st.sidebar.selectbox('Have Anaemia? (1 : True | 0 : False)',(1,0))
|
30 |
+
# Level of the CPK enzyme in the blood
|
31 |
+
creatinine_phosphokinase = st.sidebar.slider('How much is the Creatinine_Phosphokinase(CP) in the body?',20,8000,3000)
|
32 |
+
# If the patient has diabetes
|
33 |
+
diabetes = st.sidebar.selectbox('If the patient has diabetes (1 : True | 0 : False)',(1,0))
|
34 |
+
# Heart capability
|
35 |
+
ejection_fraction = st.sidebar.slider('What is the Ejection Fraction?',0,150,75)
|
36 |
+
# If the patient has hypertension
|
37 |
+
high_blood_pressure = st.sidebar.selectbox('If the patient has hypertension (1 : True | 0 : False)',(1,0))
|
38 |
+
# Platelets in the blood
|
39 |
+
platelets = st.sidebar.number_input("What is the Blood Platelets count? (kiloplatelets/mL)",0.0,100000.0)
|
40 |
+
# Level of creatinine in the blood
|
41 |
+
serum_creatinine = st.sidebar.slider('What is the level of serum creatinine in the bloodstream?',0.5,10.0,0.5)
|
42 |
+
# Level of sodium in the blood
|
43 |
+
serum_sodium = st.sidebar.slider('What is the level of Serum_Sodium in the Body?',50,200,50)
|
44 |
+
# Male or Female
|
45 |
+
sex = st.sidebar.selectbox('Gender',('Male','Female'))
|
46 |
+
# If the patient smokes
|
47 |
+
smoking = st.sidebar.selectbox('If the patient smokes (1 : True | 0 : False)',(1,0))
|
48 |
+
# Follow-up period
|
49 |
+
time = st.sidebar.slider('Follow-up period',0,400,20)
|
50 |
+
data = {'age': age,'anaemia':anaemia,'creatinine_phosphokinase':creatinine_phosphokinase,
|
51 |
+
'diabetes':diabetes,'ejection_fraction':ejection_fraction,
|
52 |
+
'high_blood_pressure':high_blood_pressure,'platelets':platelets,
|
53 |
+
'serum_creatinine':serum_creatinine,'serum_sodium':serum_sodium,
|
54 |
+
'sex':sex,'smoking':smoking,'time':time}
|
55 |
+
#
|
56 |
+
features = pd.DataFrame(data,index=[0])
|
57 |
+
return features
|
58 |
+
|
59 |
+
input_df = user_input_features()
|
60 |
+
|
61 |
+
st.subheader('Medical Data📋')
|
62 |
+
st.write(input_df)
|
63 |
+
|
64 |
+
with open('death_pred.pkl', 'rb') as file:
|
65 |
+
load_model = pickle.load(file)
|
66 |
+
|
67 |
+
# Access the individual models
|
68 |
+
model_xgboost = load_model['model_xgboost']
|
69 |
+
|
70 |
+
if st.button('Predict'):
|
71 |
+
try:
|
72 |
+
prediction = model_xgboost.predict(input_df)
|
73 |
+
prediction_proba = model_xgboost.predict_proba(input_df)
|
74 |
+
|
75 |
+
st.subheader('DIAGNOSIS')
|
76 |
+
for i in range(len(prediction)):
|
77 |
+
if prediction[i] == 0:
|
78 |
+
st.success("The patient is in good condition")
|
79 |
+
else:
|
80 |
+
st.error("This Patient is at **Risk of Death**")
|
81 |
+
|
82 |
+
st.subheader('Probability')
|
83 |
+
st.write("0 : No | 1 : Yes")
|
84 |
+
st.write(prediction_proba)
|
85 |
+
|
86 |
+
except ValueError:
|
87 |
+
st.header("Insufficient Medical Data")
|
death_pred.pkl
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:a05a5a9fd48de6623ffed2e74e37344553a7086322b944de10095394828a136e
|
3 |
+
size 201162
|
h8dsft_P1G3_AlselloDM.ipynb
ADDED
The diff for this file is too large to render.
See raw diff
|
|
requirements.txt
ADDED
@@ -0,0 +1,4 @@
|
|
|
|
|
|
|
|
|
|
|
1 |
+
streamlit
|
2 |
+
pandas
|
3 |
+
scikit-learn==1.1.1
|
4 |
+
feature_engine==1.5.2
|