Mpodszus commited on
Commit
d640ea6
·
verified ·
1 Parent(s): cae59a3

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +7 -6
app.py CHANGED
@@ -1,5 +1,4 @@
1
  import pickle
2
- import xgboost as xgb
3
  import pandas as pd
4
  import shap
5
  import gradio as gr
@@ -9,7 +8,7 @@ import matplotlib.pyplot as plt
9
  # Load the XGBoost model from Pickle
10
  loaded_model = pickle.load(open("h22_xgb_Final(2).pkl", 'rb'))
11
 
12
- # Setup SHAP Explainer for XGBoost
13
  explainer = shap.Explainer(loaded_model)
14
 
15
  def safe_convert(value, default, min_val, max_val):
@@ -75,9 +74,11 @@ def main_func(Department, ChainScale, SupportiveGM, Merit, LearningDevelopment,
75
  shap_values = explainer(new_row)
76
 
77
  fig, ax = plt.subplots(figsize=(8, 4))
78
- shap.waterfall_plot(shap.Explanation(values=shap_values.values[0],
79
- base_values=shap_values.base_values[0],
80
- data=new_row.iloc[0])) # Fix waterfall plot
 
 
81
  plt.tight_layout()
82
  local_plot = plt.gcf()
83
  plt.close()
@@ -164,4 +165,4 @@ with gr.Blocks(title=title) as demo:
164
  cache_examples=True
165
  )
166
 
167
- demo.launch()
 
1
  import pickle
 
2
  import pandas as pd
3
  import shap
4
  import gradio as gr
 
8
  # Load the XGBoost model from Pickle
9
  loaded_model = pickle.load(open("h22_xgb_Final(2).pkl", 'rb'))
10
 
11
+ # Setup SHAP Explainer for XGBoost (Do not change this)
12
  explainer = shap.Explainer(loaded_model)
13
 
14
  def safe_convert(value, default, min_val, max_val):
 
74
  shap_values = explainer(new_row)
75
 
76
  fig, ax = plt.subplots(figsize=(8, 4))
77
+ shap.waterfall_plot(shap.Explanation(
78
+ values=shap_values.values[0],
79
+ base_values=shap_values.base_values[0],
80
+ data=new_row.iloc[0]
81
+ ))
82
  plt.tight_layout()
83
  local_plot = plt.gcf()
84
  plt.close()
 
165
  cache_examples=True
166
  )
167
 
168
+ demo.launch()