hiyata commited on
Commit
4c1d061
·
verified ·
1 Parent(s): 6a3b036

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +10 -5
app.py CHANGED
@@ -149,20 +149,25 @@ def predict(file_obj):
149
  top_features.append("Others")
150
  top_values.append(others_sum)
151
 
 
152
  explanation = shap.Explanation(
153
  values=np.array(top_values),
154
- base_values=0,
155
- data=np.array([raw_freq_vector[kmer_dict[feat]] if feat != "Others" else np.sum(raw_freq_vector[others_mask]) for feat in top_features]),
 
 
 
 
156
  feature_names=top_features
157
  )
158
- explanation.expected_value = 0
159
 
160
  fig = shap.plots._waterfall.waterfall_legacy(explanation, show=False)
161
 
162
  buf = io.BytesIO()
163
  fig.savefig(buf, format='png')
164
  buf.seek(0)
165
- plot_image = Image.open(buf) # Convert BytesIO to PIL Image
166
 
167
  pred_class = 1 if probs[0][1] > probs[0][0] else 0
168
  pred_label = 'human' if pred_class == 1 else 'non-human'
@@ -196,4 +201,4 @@ iface = gr.Interface(
196
  )
197
 
198
  if __name__ == "__main__":
199
- iface.launch(share=True) # Set share=True to create a public link
 
149
  top_features.append("Others")
150
  top_values.append(others_sum)
151
 
152
+ # Set base_values and expected_value to 0.5 for the binary classification baseline
153
  explanation = shap.Explanation(
154
  values=np.array(top_values),
155
+ base_values=0.5,
156
+ data=np.array([
157
+ raw_freq_vector[kmer_dict[feat]] if feat != "Others"
158
+ else np.sum(raw_freq_vector[others_mask])
159
+ for feat in top_features
160
+ ]),
161
  feature_names=top_features
162
  )
163
+ explanation.expected_value = 0.5
164
 
165
  fig = shap.plots._waterfall.waterfall_legacy(explanation, show=False)
166
 
167
  buf = io.BytesIO()
168
  fig.savefig(buf, format='png')
169
  buf.seek(0)
170
+ plot_image = Image.open(buf)
171
 
172
  pred_class = 1 if probs[0][1] > probs[0][0] else 0
173
  pred_label = 'human' if pred_class == 1 else 'non-human'
 
201
  )
202
 
203
  if __name__ == "__main__":
204
+ iface.launch(share=True)