Spaces:
Sleeping
Sleeping
Upload folder using huggingface_hub
Browse files- app.py +46 -48
- shap_force_plot_class_0.html +0 -0
- shap_force_plot_class_1.html +0 -0
- shap_force_plot_class_2.html +0 -0
app.py
CHANGED
@@ -66,7 +66,7 @@ st.markdown(f"<h2 style='color:green;'>{predicted_repayment_interval}</h2>", uns
|
|
66 |
|
67 |
# Explanation for SHAP force plots
|
68 |
st.write("## π SHAP Explanation")
|
69 |
-
st.markdown("The following SHAP
|
70 |
|
71 |
# SHAP explanations
|
72 |
explainer = shap.TreeExplainer(model_xgb)
|
@@ -77,50 +77,48 @@ def add_background(html_content):
|
|
77 |
white_background_style = "<style>body { background-color: white; }</style>"
|
78 |
return white_background_style + html_content
|
79 |
|
80 |
-
# Generate and
|
81 |
-
|
82 |
-
st.
|
83 |
-
shap_html_path_0 = "shap_force_plot_class_0.html"
|
84 |
-
shap.save_html(shap_html_path_0, shap.force_plot(
|
85 |
-
|
86 |
-
|
87 |
-
|
88 |
-
|
89 |
-
|
90 |
-
|
91 |
-
))
|
92 |
-
with open(shap_html_path_0, 'r', encoding='utf-8') as f:
|
93 |
-
|
94 |
-
st.components.v1.html(add_background(shap_html_0), height=130)
|
95 |
-
|
96 |
-
|
97 |
-
st.write("### πͺ SHAP Force Plot for
|
98 |
-
|
99 |
-
shap_html_path_1
|
100 |
-
|
101 |
-
|
102 |
-
|
103 |
-
|
104 |
-
|
105 |
-
|
106 |
-
|
107 |
-
)
|
108 |
-
|
109 |
-
shap_html_1 =
|
110 |
-
|
111 |
-
|
112 |
-
|
113 |
-
|
114 |
-
|
115 |
-
|
116 |
-
|
117 |
-
|
118 |
-
|
119 |
-
|
120 |
-
|
121 |
-
|
122 |
-
|
123 |
-
)
|
124 |
-
|
125 |
-
shap_html_2 = f.read()
|
126 |
-
st.components.v1.html(add_background(shap_html_2), height=131)
|
|
|
66 |
|
67 |
# Explanation for SHAP force plots
|
68 |
st.write("## π SHAP Explanation")
|
69 |
+
st.markdown("The following SHAP plot explains the model's decision for the predicted repayment interval. This visualization helps you understand the key features that influenced the model's prediction.")
|
70 |
|
71 |
# SHAP explanations
|
72 |
explainer = shap.TreeExplainer(model_xgb)
|
|
|
77 |
white_background_style = "<style>body { background-color: white; }</style>"
|
78 |
return white_background_style + html_content
|
79 |
|
80 |
+
# Generate and display SHAP force plot based on the predicted repayment interval
|
81 |
+
if predicted_encoded_repayment_interval == 0:
|
82 |
+
st.write("### π
SHAP Force Plot for Bullet Repayment Interval")
|
83 |
+
shap_html_path_0 = "shap_force_plot_class_0.html"
|
84 |
+
shap.save_html(shap_html_path_0, shap.force_plot(
|
85 |
+
explainer.expected_value[0],
|
86 |
+
shap_values[0][:, 0],
|
87 |
+
X_processed.iloc[0, :].values,
|
88 |
+
feature_names,
|
89 |
+
show=False,
|
90 |
+
matplotlib=False
|
91 |
+
))
|
92 |
+
with open(shap_html_path_0, 'r', encoding='utf-8') as f:
|
93 |
+
shap_html_0 = f.read()
|
94 |
+
st.components.v1.html(add_background(shap_html_0), height=130)
|
95 |
+
|
96 |
+
elif predicted_encoded_repayment_interval == 1:
|
97 |
+
st.write("### πͺ SHAP Force Plot for Irregular Repayment Interval")
|
98 |
+
shap_html_path_1 = "shap_force_plot_class_1.html"
|
99 |
+
shap.save_html(shap_html_path_1, shap.force_plot(
|
100 |
+
explainer.expected_value[1],
|
101 |
+
shap_values[0][:, 1],
|
102 |
+
X_processed.iloc[0, :].values,
|
103 |
+
feature_names,
|
104 |
+
show=False,
|
105 |
+
matplotlib=False
|
106 |
+
))
|
107 |
+
with open(shap_html_path_1, 'r', encoding='utf-8') as f:
|
108 |
+
shap_html_1 = f.read()
|
109 |
+
st.components.v1.html(add_background(shap_html_1), height=130)
|
110 |
+
|
111 |
+
elif predicted_encoded_repayment_interval == 2:
|
112 |
+
st.write("### π
SHAP Force Plot for Monthly Repayment Interval")
|
113 |
+
shap_html_path_2 = "shap_force_plot_class_2.html"
|
114 |
+
shap.save_html(shap_html_path_2, shap.force_plot(
|
115 |
+
explainer.expected_value[2],
|
116 |
+
shap_values[0][:, 2],
|
117 |
+
X_processed.iloc[0, :].values,
|
118 |
+
feature_names,
|
119 |
+
show=False,
|
120 |
+
matplotlib=False
|
121 |
+
))
|
122 |
+
with open(shap_html_path_2, 'r', encoding='utf-8') as f:
|
123 |
+
shap_html_2 = f.read()
|
124 |
+
st.components.v1.html(add_background(shap_html_2), height=130)
|
|
|
|
shap_force_plot_class_0.html
CHANGED
The diff for this file is too large to render.
See raw diff
|
|
shap_force_plot_class_1.html
CHANGED
The diff for this file is too large to render.
See raw diff
|
|
shap_force_plot_class_2.html
CHANGED
The diff for this file is too large to render.
See raw diff
|
|