pavanmutha commited on
Commit
2f1ab5b
·
verified ·
1 Parent(s): a7c29e7

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +16 -15
app.py CHANGED
@@ -125,22 +125,23 @@ def explainability(_):
125
  else:
126
  sv = shap_values
127
 
128
- # Use safe feature names if mismatch, fallback to dummy
129
- num_features = sv.shape[1]
130
- if num_features <= X_test.shape[1]:
131
- feature_names = X_test.columns[:num_features]
132
- else:
133
- feature_names = [f"Feature_{i}" for i in range(num_features)]
134
-
135
- X_shap_safe = pd.DataFrame(np.zeros_like(sv), columns=feature_names)
 
 
 
 
 
 
 
 
136
 
137
- shap.summary_plot(sv, X_shap_safe, show=False)
138
- shap_path = "./shap_plot.png"
139
- plt.title("SHAP Summary")
140
- plt.savefig(shap_path)
141
- if wandb.run:
142
- wandb.log({"shap_summary": wandb.Image(shap_path)})
143
- plt.clf()
144
 
145
 
146
  except Exception as e:
 
125
  else:
126
  sv = shap_values
127
 
128
+ # Use safe feature names if mismatch, fallback to dummy
129
+ num_features = sv.shape[1]
130
+ if num_features <= X_test.shape[1]:
131
+ feature_names = X_test.columns[:num_features]
132
+ else:
133
+ feature_names = [f"Feature_{i}" for i in range(num_features)]
134
+
135
+ X_shap_safe = pd.DataFrame(np.zeros_like(sv), columns=feature_names)
136
+
137
+ shap.summary_plot(sv, X_shap_safe, show=False)
138
+ shap_path = "./shap_plot.png"
139
+ plt.title("SHAP Summary")
140
+ plt.savefig(shap_path)
141
+ if wandb.run:
142
+ wandb.log({"shap_summary": wandb.Image(shap_path)})
143
+ plt.clf()
144
 
 
 
 
 
 
 
 
145
 
146
 
147
  except Exception as e: