Update src/streamlit_app.py
Browse files- src/streamlit_app.py +9 -8
src/streamlit_app.py
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
|
|
| 1 |
import os
|
| 2 |
import joblib
|
| 3 |
import numpy as np
|
|
@@ -9,7 +10,7 @@ import tempfile
|
|
| 9 |
import streamlit.components.v1 as components
|
| 10 |
import scipy.sparse as sp
|
| 11 |
|
| 12 |
-
# Setup
|
| 13 |
API_URL = os.getenv('API_URL')
|
| 14 |
NUMERIC_FEATURES = ['age','alcohol_consumption_per_week','physical_activity_minutes_per_week',
|
| 15 |
'diet_score','bmi','cholesterol_total','insulin_level','map','glucose_fasting']
|
|
@@ -21,7 +22,7 @@ st.set_page_config(page_title="Diabetes Predictions", layout="wide")
|
|
| 21 |
|
| 22 |
# Function for SHAP plot
|
| 23 |
def st_shap(plot, height=None):
|
| 24 |
-
"""Renders a SHAP plot in Streamlit using
|
| 25 |
import tempfile, os
|
| 26 |
with tempfile.NamedTemporaryFile(delete=False, suffix=".html") as tmpfile:
|
| 27 |
shap.save_html(tmpfile.name, plot)
|
|
@@ -42,11 +43,11 @@ def st_shap(plot, height=None):
|
|
| 42 |
|
| 43 |
components.html(styled_html, height=height or 500, width=1000, scrolling=True)
|
| 44 |
|
| 45 |
-
def _to_dense(X):
|
| 46 |
-
|
| 47 |
-
|
| 48 |
-
|
| 49 |
-
|
| 50 |
|
| 51 |
# Function to create synthetic data
|
| 52 |
def synth_data(n_policyholders=100, seed=42):
|
|
@@ -154,7 +155,7 @@ else:
|
|
| 154 |
shap_plot = shap.force_plot(
|
| 155 |
explainer.expected_value,
|
| 156 |
shap_values[0],
|
| 157 |
-
|
| 158 |
matplotlib=False,
|
| 159 |
feature_names=feature_names
|
| 160 |
)
|
|
|
|
| 1 |
+
# Import packages
|
| 2 |
import os
|
| 3 |
import joblib
|
| 4 |
import numpy as np
|
|
|
|
| 10 |
import streamlit.components.v1 as components
|
| 11 |
import scipy.sparse as sp
|
| 12 |
|
| 13 |
+
# Setup API and features
|
| 14 |
API_URL = os.getenv('API_URL')
|
| 15 |
NUMERIC_FEATURES = ['age','alcohol_consumption_per_week','physical_activity_minutes_per_week',
|
| 16 |
'diet_score','bmi','cholesterol_total','insulin_level','map','glucose_fasting']
|
|
|
|
| 22 |
|
| 23 |
# Function for SHAP plot
|
| 24 |
def st_shap(plot, height=None):
|
| 25 |
+
"""Renders a SHAP plot in Streamlit using HTML style and white background."""
|
| 26 |
import tempfile, os
|
| 27 |
with tempfile.NamedTemporaryFile(delete=False, suffix=".html") as tmpfile:
|
| 28 |
shap.save_html(tmpfile.name, plot)
|
|
|
|
| 43 |
|
| 44 |
components.html(styled_html, height=height or 500, width=1000, scrolling=True)
|
| 45 |
|
| 46 |
+
#def _to_dense(X):
|
| 47 |
+
# """Ensure X is a dense NumPy array (convert from sparse if needed)."""
|
| 48 |
+
# if sp.issparse(X):
|
| 49 |
+
# return X.toarray()
|
| 50 |
+
# return np.asarray(X)
|
| 51 |
|
| 52 |
# Function to create synthetic data
|
| 53 |
def synth_data(n_policyholders=100, seed=42):
|
|
|
|
| 155 |
shap_plot = shap.force_plot(
|
| 156 |
explainer.expected_value,
|
| 157 |
shap_values[0],
|
| 158 |
+
X_row[0],
|
| 159 |
matplotlib=False,
|
| 160 |
feature_names=feature_names
|
| 161 |
)
|