Tryfonas commited on
Commit
46e3a93
β€’
1 Parent(s): f53bd5e

Upload folder using huggingface_hub

Browse files
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 plots explain the model's decision for each repayment interval type. These visualizations help you understand the key features that influenced the model's prediction.")
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 save SHAP force plot for Class 0 (Bullet)
81
- st.write("### πŸš… SHAP Force Plot for Class 0: Bullet Repayment Interval")
82
- st.markdown("This plot explains the factors influencing the Bullet repayment interval prediction. Bullet repayment means paying off the loan in one lump sum at the end of the loan period.")
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
- # Generate and save SHAP force plot for Class 1 (Irregular)
97
- st.write("### πŸͺ™ SHAP Force Plot for Class 1: Irregular Repayment Interval")
98
- st.markdown("This plot explains the factors influencing the Irregular repayment interval prediction. Irregular repayment means paying off the loan at irregular intervals based on specific conditions.")
99
- shap_html_path_1 = "shap_force_plot_class_1.html"
100
- shap.save_html(shap_html_path_1, shap.force_plot(
101
- explainer.expected_value[1],
102
- shap_values[0][:, 1],
103
- X_processed.iloc[0, :].values,
104
- feature_names,
105
- show=False,
106
- matplotlib=False
107
- ))
108
- with open(shap_html_path_1, 'r', encoding='utf-8') as f:
109
- shap_html_1 = f.read()
110
- st.components.v1.html(add_background(shap_html_1), height=130)
111
-
112
- # Generate and save SHAP force plot for Class 2 (Monthly)
113
- st.write("### πŸ“… SHAP Force Plot for Class 2: Monthly Repayment Interval")
114
- st.markdown("This plot explains the factors influencing the Monthly repayment interval prediction. Monthly repayment means paying off the loan in equal monthly installments.")
115
- shap_html_path_2 = "shap_force_plot_class_2.html"
116
- shap.save_html(shap_html_path_2, shap.force_plot(
117
- explainer.expected_value[2],
118
- shap_values[0][:, 2],
119
- X_processed.iloc[0, :].values,
120
- feature_names,
121
- show=False,
122
- matplotlib=False
123
- ))
124
- with open(shap_html_path_2, 'r', encoding='utf-8') as f:
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