Spaces:
Sleeping
Sleeping
Commit
·
eecbbf8
1
Parent(s):
75a71aa
update app
Browse files- app.py +41 -0
- model/drug_pipeline.sav +0 -0
- results/metrics.txt +1 -1
- results/model_result.png +0 -0
- train.py +6 -1
- utils/__init__.py +0 -0
- utils/__pycache__/__init__.cpython-310.pyc +0 -0
- utils/__pycache__/prediction.cpython-310.pyc +0 -0
- utils/prediction.py +19 -0
app.py
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import streamlit as st
|
| 2 |
+
import numpy as np
|
| 3 |
+
import pickle
|
| 4 |
+
from utils.prediction import predict_drug
|
| 5 |
+
|
| 6 |
+
|
| 7 |
+
# Loading the model
|
| 8 |
+
filename = "./model/drug_pipeline.sav"
|
| 9 |
+
pipe = pickle.load(open(filename, 'rb'))
|
| 10 |
+
|
| 11 |
+
|
| 12 |
+
# Web interface section
|
| 13 |
+
st.title("Drug Classifier")
|
| 14 |
+
|
| 15 |
+
# Singular prediction
|
| 16 |
+
with st.sidebar.expander("Single Prediction"):
|
| 17 |
+
with st.form(key="drug_form", clear_on_submit=True):
|
| 18 |
+
st.title("Drug Information Form")
|
| 19 |
+
age = st.number_input(label="Age", min_value=15, step=1, max_value=74)
|
| 20 |
+
|
| 21 |
+
gender_list = np.array(["Male", "Female"])
|
| 22 |
+
gender = st.radio("Select your Gender", gender_list)
|
| 23 |
+
|
| 24 |
+
blood_pressure_list = np.array(["HIGH", "LOW", "NORMAL"])
|
| 25 |
+
blood_pressure = st.radio("Select your Blood pressure", blood_pressure_list)
|
| 26 |
+
|
| 27 |
+
cholesterol_list = np.array(["HIGH", "NORMAL"])
|
| 28 |
+
cholesterol = st.radio("Select your Cholesterol", cholesterol_list)
|
| 29 |
+
|
| 30 |
+
Na_to_k = st.number_input(label="NA_to_K", min_value=6.2, step=0.1, max_value=38.2)
|
| 31 |
+
submit_button = st.form_submit_button(label="Predict")
|
| 32 |
+
|
| 33 |
+
if submit_button:
|
| 34 |
+
prediction = predict_drug(age, gender[0], blood_pressure, cholesterol, Na_to_k, pipe)
|
| 35 |
+
|
| 36 |
+
if prediction is None:
|
| 37 |
+
st.error("An error occurred while getting the prediction!")
|
| 38 |
+
|
| 39 |
+
message = f"The Drug is {prediction}!"
|
| 40 |
+
message_color = 'red' if prediction == 1 else 'green'
|
| 41 |
+
st.markdown(f"<h3 style='text-align: left;color:{message_color}'> {(message)} </h3>", unsafe_allow_html=True)
|
model/drug_pipeline.sav
ADDED
|
Binary file (40.3 kB). View file
|
|
|
results/metrics.txt
CHANGED
|
@@ -1,2 +1,2 @@
|
|
| 1 |
|
| 2 |
-
Accuracy=0.
|
|
|
|
| 1 |
|
| 2 |
+
Accuracy=0.95, F1_score = 0.89
|
results/model_result.png
CHANGED
|
|
train.py
CHANGED
|
@@ -63,4 +63,9 @@ with open("./results/metrics.txt", "w") as outfile:
|
|
| 63 |
outfile.write(f"\nAccuracy={round(accuracy, 2)}, F1_score = {round(f1, 2)}")
|
| 64 |
|
| 65 |
# Save the model
|
| 66 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 63 |
outfile.write(f"\nAccuracy={round(accuracy, 2)}, F1_score = {round(f1, 2)}")
|
| 64 |
|
| 65 |
# Save the model
|
| 66 |
+
import pickle
|
| 67 |
+
# save the model to disk
|
| 68 |
+
filename = './model/drug_pipeline.sav'
|
| 69 |
+
pickle.dump(pipe, open(filename, 'wb'))
|
| 70 |
+
|
| 71 |
+
#sio.dump(pipe, "./model/drug_pipeline.skops")
|
utils/__init__.py
ADDED
|
File without changes
|
utils/__pycache__/__init__.cpython-310.pyc
ADDED
|
Binary file (169 Bytes). View file
|
|
|
utils/__pycache__/prediction.cpython-310.pyc
ADDED
|
Binary file (644 Bytes). View file
|
|
|
utils/prediction.py
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
|
| 2 |
+
def predict_drug(age, sex, blood_pressure, cholesterol, na_to_k_ratio, pipe):
|
| 3 |
+
"""
|
| 4 |
+
Predict drugs based on patient features.
|
| 5 |
+
|
| 6 |
+
:param age:
|
| 7 |
+
:param sex:
|
| 8 |
+
:param blood_pressure:
|
| 9 |
+
:param cholesterol:
|
| 10 |
+
:param na_to_k_ratio:
|
| 11 |
+
:return: str: Predicted drug label.
|
| 12 |
+
|
| 13 |
+
"""
|
| 14 |
+
|
| 15 |
+
features = [age, sex, blood_pressure, cholesterol, na_to_k_ratio]
|
| 16 |
+
predicted_drug = pipe.predict([features])[0]
|
| 17 |
+
|
| 18 |
+
label = f"Predicted Drug: {predicted_drug}"
|
| 19 |
+
return label
|