Spaces:
Sleeping
Sleeping
File size: 4,561 Bytes
3294074 | 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 | import streamlit as st
import joblib
import os
import numpy as np
attrib_info = """
#### Attribute Information:
- Age 1.20-65
- Sex 1. Male, 2.Female
- Polyuria 1.Yes, 2.No.
- Polydipsia 1.Yes, 2.No.
- sudden weight loss 1.Yes, 2.No.
- weakness 1.Yes, 2.No.
- Polyphagia 1.Yes, 2.No.
- Genital thrush 1.Yes, 2.No.
- visual blurring 1.Yes, 2.No.
- Itching 1.Yes, 2.No.
- Irritability 1.Yes, 2.No.
- delayed healing 1.Yes, 2.No.
- partial paresis 1.Yes, 2.No.
- muscle stiness 1.Yes, 2.No.
- Alopecia 1.Yes, 2.No.
- Obesity 1.Yes, 2.No.
- Class 1.Positive, 2.Negative.
"""
label_dict = {"No":0,"Yes":1}
gender_map={"Female":0, "Male":1}
target_label_map = {"Negative":0,"Positive":1}
def get_fvalue(val):
feature_dict={"No":0, "Yes":1}
for key, value in feature_dict.items():
if val==key:
return value
def get_value(val, my_dict):
for key, value in my_dict.items():
if val==key:
return value
@st.cache_data
def load_model(model_file):
loaded_model=joblib.load(open(os.path.join(model_file), "rb"))
return loaded_model
def run_ml_app():
st.subheader("From ML Prediction")
with st.expander("Attribute Info"):
st.markdown(attrib_info)
col1, col2= st.columns(2)
with col1:
age = st.number_input("Age",10,100)
gender = st.radio("Gender",("Female","Male"))
polyuria = st.radio("Polyuria",["No","Yes"])
polydipsia = st.radio("Polydipsia",["No","Yes"])
sudden_weight_loss = st.selectbox("Sudden_weight_loss",["No","Yes"])
weakness = st.radio("weakness",["No","Yes"])
polyphagia = st.radio("polyphagia",["No","Yes"])
genital_thrush = st.selectbox("Genital_thrush",["No","Yes"])
with col2:
visual_blurring = st.selectbox("Visual_blurring",["No","Yes"])
itching = st.radio("itching",["No","Yes"])
irritability = st.radio("irritability",["No","Yes"])
delayed_healing = st.radio("delayed_healing",["No","Yes"])
partial_paresis = st.selectbox("Partial_paresis",["No","Yes"])
muscle_stiffness = st.radio("muscle_stiffness",["No","Yes"])
alopecia = st.radio("alopecia",["No","Yes"])
obesity = st.select_slider("obesity",["No","Yes"])
with st.expander("Your Selected Options"):
result={"Age":age,
"gender":gender,
"polyuria":polyuria,
"polydipsia":polydipsia,
"sudden_weight_loss":sudden_weight_loss,
"weakness":weakness,
"polyphagia":polyphagia,
"genital_thrush":genital_thrush,
"visual_blurring":visual_blurring,
"itching":itching,
"irritability": irritability,
"delayed_healing":delayed_healing,
"partial_paresis":partial_paresis,
"muscle_stiffness":muscle_stiffness,
"alopecia":alopecia,
"obesity":obesity}
st.write("In JSON format:")
st.write(result)
encoded_result=[]
for i in result.values():
if type(i)==int:
encoded_result.append(i)
elif i in ["Female","Male"]:
res=get_value(i,gender_map)
encoded_result.append(res)
else:
encoded_result.append(get_fvalue(i))
st.write("In LIST format")
st.write(encoded_result)
with st.expander("Prediction Results"):
single_sample=np.array(encoded_result).reshape(1,-1)
st.write(single_sample)
model=load_model("models/logistic_regression_model_diabetes_21_oct_2020.pkl")
prediction=model.predict(single_sample)
pred_prob=model.predict_proba(single_sample)
st.write(prediction)
st.write(pred_prob)
if prediction==1:
st.warning("Positive Risk {}".format(prediction[0]))
pred_probability_score={"Negative DM Risk":round(pred_prob[0][0]*100,2), "Positive DM Risk":round(pred_prob[0][1]*100,2)}
st.write(pred_probability_score)
else:
st.success("Negative Risk {}".format(prediction[0]))
pred_probability_score={"Negative DM Risk":round(pred_prob[0][0]*100,2), "Positive DM Risk":round(pred_prob[0][1]*100,2)}
st.write(pred_probability_score) |