From 00e99e5464d2da7d88ec5f9e2551b9580a90eb99 Mon Sep 17 00:00:00 2001 From: toto Date: Thu, 9 Apr 2026 22:49:48 +0200 Subject: [PATCH] fix(bot-detector): make scoring functions public (remove underscore prefix) compute_shap_top_features, build_reason, cluster_anomalies renamed from private (_prefixed) to public to match pipeline.py imports. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --- services/bot-detector/bot_detector/scoring.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/services/bot-detector/bot_detector/scoring.py b/services/bot-detector/bot_detector/scoring.py index 09dd0e1..6dcd516 100644 --- a/services/bot-detector/bot_detector/scoring.py +++ b/services/bot-detector/bot_detector/scoring.py @@ -186,7 +186,7 @@ def normalize_scores(scores: np.ndarray) -> np.ndarray: # A4 — EXPLAINABILITÉ SHAP # ═══════════════════════════════════════════════════════════════════════════════ -def _compute_shap_top_features(model, X: pd.DataFrame, features: list, +def compute_shap_top_features(model, X: pd.DataFrame, features: list, n_top: int = 5) -> list: """ Calcule les valeurs SHAP pour chaque ligne de X et retourne les n_top features @@ -216,7 +216,7 @@ def _compute_shap_top_features(model, X: pd.DataFrame, features: list, return [{}] * len(X) -def _build_reason(name: str, row: pd.Series, shap_top: dict) -> str: +def build_reason(name: str, row: pd.Series, shap_top: dict) -> str: """Construit le champ reason enrichi avec le top SHAP ou les métriques clés.""" # Utilise le score brut pour l'affichage (plus interprétable que le score normalisé) score = round(float(row.get('raw_anomaly_score', row.get('anomaly_score', 0))), 3) @@ -233,7 +233,7 @@ def _build_reason(name: str, row: pd.Series, shap_top: dict) -> str: # A8 — CLUSTERING COMPORTEMENTAL DES ANOMALIES # ═══════════════════════════════════════════════════════════════════════════════ -def _cluster_anomalies(anomalies: pd.DataFrame, features: list, +def cluster_anomalies(anomalies: pd.DataFrame, features: list, ae_model=None) -> pd.DataFrame: """A8 : Applique HDBSCAN (ou DBSCAN en fallback) sur les features normalisées des anomalies.