Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,8 +1,6 @@
|
|
| 1 |
import streamlit as st
|
| 2 |
import pandas as pd
|
| 3 |
import joblib
|
| 4 |
-
import shap
|
| 5 |
-
import matplotlib.pyplot as plt
|
| 6 |
|
| 7 |
# Load the model
|
| 8 |
@st.cache_resource
|
|
@@ -15,7 +13,7 @@ model = load_model()
|
|
| 15 |
st.title("Retention Probability Predictor")
|
| 16 |
st.markdown("""
|
| 17 |
Predict the probability of retention based on patient and treatment details.
|
| 18 |
-
Provide the required inputs below to see the prediction
|
| 19 |
""")
|
| 20 |
|
| 21 |
# Sidebar for inputs
|
|
@@ -85,25 +83,3 @@ if st.sidebar.button("Predict Retention Probability"):
|
|
| 85 |
st.subheader("Calculated Features")
|
| 86 |
st.write(f"**Failed Buprenorphine Rate:** {Failed_Bup_Rate:.2%}")
|
| 87 |
st.write(f"**Proportion of Days Covered:** {proportionofDaysCovered:.2%}")
|
| 88 |
-
|
| 89 |
-
# Explain model prediction using SHAP
|
| 90 |
-
st.subheader("Feature Contribution to Prediction")
|
| 91 |
-
explainer = shap.Explainer(model, input_data) # Create a SHAP explainer
|
| 92 |
-
shap_values = explainer(input_data)
|
| 93 |
-
|
| 94 |
-
# Plot feature importance
|
| 95 |
-
shap.force_plot(
|
| 96 |
-
explainer.expected_value[1],
|
| 97 |
-
shap_values.values[0],
|
| 98 |
-
input_data.iloc[0],
|
| 99 |
-
matplotlib=True,
|
| 100 |
-
show=False
|
| 101 |
-
)
|
| 102 |
-
st.pyplot(plt.gcf()) # Display SHAP force plot
|
| 103 |
-
|
| 104 |
-
st.write("The above visualization shows how each feature contributes to the prediction.")
|
| 105 |
-
|
| 106 |
-
# Feature importance bar chart
|
| 107 |
-
st.subheader("Feature Importance (Bar Chart)")
|
| 108 |
-
shap.summary_plot(shap_values, input_data, plot_type="bar", show=False)
|
| 109 |
-
st.pyplot(plt.gcf())
|
|
|
|
| 1 |
import streamlit as st
|
| 2 |
import pandas as pd
|
| 3 |
import joblib
|
|
|
|
|
|
|
| 4 |
|
| 5 |
# Load the model
|
| 6 |
@st.cache_resource
|
|
|
|
| 13 |
st.title("Retention Probability Predictor")
|
| 14 |
st.markdown("""
|
| 15 |
Predict the probability of retention based on patient and treatment details.
|
| 16 |
+
Provide the required inputs below to see the prediction.
|
| 17 |
""")
|
| 18 |
|
| 19 |
# Sidebar for inputs
|
|
|
|
| 83 |
st.subheader("Calculated Features")
|
| 84 |
st.write(f"**Failed Buprenorphine Rate:** {Failed_Bup_Rate:.2%}")
|
| 85 |
st.write(f"**Proportion of Days Covered:** {proportionofDaysCovered:.2%}")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|