Repository navigation
Description
Task
T-072· Milestone M6 — Analysis + risk · Size M · Priority P0 · Epic #6Implements FR-ANA-003 · PR-06
Branch
feat/t-072-importance-histgradientboosting-shap-global-interactions— one task = one branch = one PR (doc 32 §6)
Summary
Implement analysis/importance.py ImportanceExplainer.explain() per doc 09 §4.1–4.2: balanced HistGB classifier on u, 5-fold stratified CV (ROC-AUC, balanced accuracy, low-confidence flag if n_fail < min_failures_confident), mean |SHAP|, pairwise interaction strength via shap_interaction_values, ARD 1/ℓ_j comparison with disagreement flag, per-mode importance.
Context / motivation
Answers why failures happen and which parameter combinations matter (H3).
Scope
In scope
- Fallback to
GradientBoostingClassifierif SHAP/HistGB versions mismatch. ImportanceReportmodel.ImportanceSettingsmodel with the new keys.
Implementation guidance
- Module
roboprobe/analysis/importance.py:class ImportanceExplainer: def __init__(self, settings: ImportanceSettings, seed: int) -> None; def explain(self, X: NDArray, y_fail: NDArray[np.bool_], names: list[str], gp: RobustnessGP | None = None, modes: Sequence[FailureModeSummary] = ()) -> ImportanceReport(doc 05 §7). - Model:
HistGradientBoostingClassifier(max_depth, learning_rate, max_iter from analysis.gbm, class_weight="balanced", random_state=seed)on unit-spaceXof all valid runs (FAIL vs PASS). - Quality:
StratifiedKFold(analysis.cv_folds, shuffle=True, random_state=seed)→ ROC-AUC and balanced accuracy (mean ± std);low_confidence = n_fail < analysis.min_failures_confident or auc < 0.7(AUC floor as settinganalysis.min_cv_auc, new). - SHAP:
shap.TreeExplainer(model); global importance = mean |SHAP|; interactions viashap_interaction_valueson a sample ofanalysis.shap_max_samples(new, default 1000) rows → symmetricd×dstrength matrix (off-diagonal mean |value|). - GP cross-check:
1/ℓ_jfrom the ARD kernel (T-055a) normalised to sum 1; flag parameters whose rank differs by ≥ 2 positions (disagreement=True). - Per-mode importance: one-vs-rest model per mode with ≥
min_failures_confidentmembers. ImportanceReportserialisable to JSON (lists, not arrays) forreport.jsonand the/importanceendpoint.- Fallback if SHAP's tree support doesn't cover the installed sklearn version:
GradientBoostingClassifier+ same explainer; recordmodel_kindin the report. - Standards: respect the layering contracts (doc 16 §2) and conventions in doc 34; no hard-coded tunables — thresholds/defaults come from typed settings (doc 27); no magic numbers (ruff
PLR2004); public APIs typed (mypy strict) and documented.
Configuration keys
From the configuration reference (doc 27). Keys marked (new) must be added to the typed settings models and appear in the generated reference (T-003c).
analysis.gbmanalysis.cv_foldsanalysis.min_failures_confident- analysis.min_cv_auc (new)
- analysis.shap_max_samples (new)
Acceptance criteria
- Planted-parameter synthetic data: planted params ranked top-k; planted interaction pair has highest interaction strength.
- Low-confidence flag works.
- Report JSON validates against
schemas/analysis_report.schema.jsonimportance block (T-075a). - Low-confidence flag tested for both triggers.
- Deterministic for fixed seed (two runs → equal JSON).
- Runtime < 30 s for 2 000 runs, d = 8 (benchmark marker).
- Tests listed below added and green in CI; coverage of new code meets the gate in doc 18 §3.
- Docs, config reference and CHANGELOG
Unreleasedupdated where behaviour, keys or interfaces changed. - Definition of Done (doc 32 §3) satisfied.
Tests required
tests/unit/analysis/test_importance.py.- Synthetic planted-parameter dataset generator in
tests/fixtures/analysis/synthetic.py(shared with T-073).
Dependencies
Blocked by: #110 (T-055a)
Blocks: #132 (T-073), #137 (T-075a)
Parallelization notes
Files / paths owned by this task — avoid editing other paths; shared files (pyproject.toml entry points, cli/main.py, api/routers/__init__.py, router.tsx, docker/compose.yaml, ci.yml) are append-only:
backend/src/roboprobe/analysis/importance.py
Independent of clustering stream.
Definition of Done
Per doc 32 §3 and AGENTS.md §5: lint, format, mypy strict and import-linter green; tests added and passing; docs updated; PR template completed with Closes #<this issue>; Conventional Commit messages referencing T-072 (doc 16 §6); commits authored only by the repository owner identity (AGENTS.md §4); CI green; reviewer checklist (doc 32 §5.1) satisfied.
References
Design docs: doc 09 §4 · doc 09 §4.1 · doc 09 §4.2 · doc 18 §4.6 · ADR-0012 · doc 05 §7 · doc 27 §4.8
Requirements: FR-ANA-003 · PR-06 (traceability: doc 28)
External:
Metadata
Metadata
Assignees
Labels
Projects
- StatusShow more project fieldsBacklog
Activity
report.jsonand analysis artefacts #137