Spaces:
Sleeping
Sleeping
Deploy backend Flask app
Browse files- bot_detector_api.py +6 -1
bot_detector_api.py
CHANGED
|
@@ -96,7 +96,12 @@ def generate_shap_bot_attack_paragraph(index, shap_values, X, encoders=None, cla
|
|
| 96 |
|
| 97 |
# Rank by contribution
|
| 98 |
feature_contribs = list(zip(feature_names, decoded_vals.values(), shap_vals))
|
| 99 |
-
feature_contribs = sorted(
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 100 |
|
| 101 |
positive_impacts = []
|
| 102 |
negative_impacts = []
|
|
|
|
| 96 |
|
| 97 |
# Rank by contribution
|
| 98 |
feature_contribs = list(zip(feature_names, decoded_vals.values(), shap_vals))
|
| 99 |
+
feature_contribs = sorted(
|
| 100 |
+
feature_contribs,
|
| 101 |
+
key=lambda x: abs(float(x[2])), # ensure it's a scalar
|
| 102 |
+
reverse=True
|
| 103 |
+
)[:top_n]
|
| 104 |
+
|
| 105 |
|
| 106 |
positive_impacts = []
|
| 107 |
negative_impacts = []
|