Skip to content

Commit 8bbcea6

Browse files
Fix sklearn tree importances retrieval bug (#377)
When obtaining the tree feature kpis we access the JSON report path `treePreparationReport.variablesStatistics`. If there are informative variables but no informative tree `variablesStatistics` is not defined. We didn't check that and it lead to a bug in this rare case.
1 parent 6373ff5 commit 8bbcea6

File tree

2 files changed

+11
-4
lines changed

2 files changed

+11
-4
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@
1111
### Added
1212
- (`sklearn`) Support for boolean and float targets in `KhiopsClassifier`.
1313

14+
### Fixed
15+
- (`sklearn`) Crash when there were no informative trees in predictors.
16+
1417
## 10.3.0.0 - 2025-02-10
1518

1619
### Fixed

khiops/sklearn/estimators.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1674,10 +1674,14 @@ def _fit_training_post_process(self, ds):
16741674
else:
16751675
pair_feature_evaluated_names_ = []
16761676
pair_feature_evaluated_levels_ = []
1677-
if "treePreparationReport" in self.model_report_raw_:
1678-
tree_preparation_report = self.model_report_raw_["treePreparationReport"][
1679-
"variablesStatistics"
1680-
]
1677+
if (
1678+
"treePreparationReport" in self.model_report_.json_data
1679+
and "variablesStatistics"
1680+
in self.model_report_.json_data["treePreparationReport"]
1681+
):
1682+
tree_preparation_report = self.model_report_.json_data[
1683+
"treePreparationReport"
1684+
]["variablesStatistics"]
16811685
tree_feature_evaluated_names_ = [
16821686
tree_preparation_report[i]["name"]
16831687
for i in range(0, len(tree_preparation_report))

0 commit comments

Comments
 (0)