|
import streamlit as st |
|
import pandas as pd |
|
import pickle |
|
|
|
|
|
|
|
st.write(""" |
|
# DEATH PREDICTION APP |
|
|
|
This app predicts the likelihood of a patient's **Death** . |
|
|
|
""") |
|
|
|
@st.cache_data |
|
def fetch_data(): |
|
df = pd.read_csv('h8dsft_P1G3_AlselloDM.csv') |
|
return df |
|
|
|
df = fetch_data() |
|
|
|
st.sidebar.title("Patient's Medical Records") |
|
st.sidebar.write('Please enter the condition here') |
|
st.sidebar.title("Prediction Form📋") |
|
|
|
def user_input_features(): |
|
|
|
age = st.sidebar.number_input("Age of the patient", 1,100) |
|
|
|
anaemia = st.sidebar.selectbox('Have Anaemia? (1 : True | 0 : False)',(1,0)) |
|
|
|
creatinine_phosphokinase = st.sidebar.slider('How much is the Creatinine_Phosphokinase(CP) in the body?',20,8000,3000) |
|
|
|
diabetes = st.sidebar.selectbox('If the patient has diabetes (1 : True | 0 : False)',(1,0)) |
|
|
|
ejection_fraction = st.sidebar.slider('What is the Ejection Fraction?',0,150,75) |
|
|
|
high_blood_pressure = st.sidebar.selectbox('If the patient has hypertension (1 : True | 0 : False)',(1,0)) |
|
|
|
platelets = st.sidebar.number_input("What is the Blood Platelets count? (kiloplatelets/mL)",0.0,100000.0) |
|
|
|
serum_creatinine = st.sidebar.slider('What is the level of serum creatinine in the bloodstream?',0.5,10.0,0.5) |
|
|
|
serum_sodium = st.sidebar.slider('What is the level of Serum_Sodium in the Body?',50,200,50) |
|
|
|
sex = st.sidebar.selectbox('Gender',('Male','Female')) |
|
|
|
smoking = st.sidebar.selectbox('If the patient smokes (1 : True | 0 : False)',(1,0)) |
|
|
|
time = st.sidebar.slider('Follow-up period',0,400,20) |
|
data = {'age': age,'anaemia':anaemia,'creatinine_phosphokinase':creatinine_phosphokinase, |
|
'diabetes':diabetes,'ejection_fraction':ejection_fraction, |
|
'high_blood_pressure':high_blood_pressure,'platelets':platelets, |
|
'serum_creatinine':serum_creatinine,'serum_sodium':serum_sodium, |
|
'sex':sex,'smoking':smoking,'time':time} |
|
|
|
features = pd.DataFrame(data,index=[0]) |
|
return features |
|
|
|
input_df = user_input_features() |
|
|
|
st.subheader('Medical Data📋') |
|
st.write(input_df) |
|
|
|
with open('death_pred.pkl', 'rb') as file: |
|
load_model = pickle.load(file) |
|
|
|
|
|
model_xgboost = load_model['model_xgboost'] |
|
|
|
if st.button('Predict'): |
|
try: |
|
prediction = model_xgboost.predict(input_df) |
|
prediction_proba = model_xgboost.predict_proba(input_df) |
|
|
|
st.subheader('DIAGNOSIS') |
|
for i in range(len(prediction)): |
|
if prediction[i] == 0: |
|
st.success("The patient is in good condition") |
|
else: |
|
st.error("This Patient is at **Risk of Death**") |
|
|
|
st.subheader('Probability') |
|
st.write("0 : No | 1 : Yes") |
|
st.write(prediction_proba) |
|
|
|
except ValueError: |
|
st.header("Insufficient Medical Data") |
|
|