fix(dtrees): use the real right-child impurity for best-first leaf priority #3772
All Vouch review confidence checks passed
Residual risk 0.16 = Change Risk (0.40) × (1 − Review Confidence (0.60)).
Review depth and reviewer attention state are adequate.
Model 1 · Change Risk (XGBoost)
Score: 0.40 · 301 lines diff across 3 files
Model 2 · Review Depth (DistilBERT)
Depth Score: 0.17 · 1 substantive comment(s)
Model 3 · Review Timing & Attention
Session adequacy: 100% · Reviewer familiarity: 35%
Bedrock Claude 3 · Risk Narration
(disconnected)
Groq Risk Narration
AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
Model 1 · Change Risk Attribution
SHAP Weights
Diff Size
diff_size
0.342
Shallow Review Depth
shallow_review_depth
0.289
Real PR Conversation Timeline
1 comments
"Review active on #3772"
general
weight: 0.35
avolkov-intel
Summary
Partially fixes #3771 — see #3773 for the rest (a second, independent bug in the same area, found while validating this fix).
buildNode(used bybuildBestFirstto rank pending leaves undermax_leaf_nodes) computed the leaf-expansion priority as:Two bugs stacked here:
1.
item.leftWeightswas read before it was ever set for the split being evaluated (it's only assignedsplit.leftWeightsfurther down). Every freshly builtWorkIteminitializesleftWeightsto0.0, soimprovealways collapsed tototalWeights impLeft, ignoring the right child entirely.2. The right-child impurity was approximated as
(imp - impLeft)instead of the actual computed right-child impurity — only exact if the parent's impurity equals the weighted average of the children's, which does not hold in general for Gini/variance impurity.This made
buildBestFirstpick a different (and lower-quality) leaf to expand next than sklearn'sBestFirstTreeBuilderwould, for the samemax_leaf_nodesbudget — same tree size, worse fit.Fix
Use
split.leftWeights(notitem.leftWeights), and compute the real right-child impurity via the existingconvertLeftImpToRighthelper before the priority check instead of approximating it.nLeft/leftWeights/left-impurity are captured before that call since it mutatessplitin place to hold the right-child data.buildDepthFirst's termination check (split.totalWeights split.impurityDecrease < minImpurityDecrease) doesn't go through this code path, which is why depth-first growth (max_depth,min_samples_split, unconstrained) already matched sklearn exactly and onlymax_leaf_nodeswas affected.Test plan
max_leaf_nodes=42Brier error vs. sklearn drops from +23.0% to +8.7% with this fix alone (remaining gap is #3773, fixed separately).cpp/oneapi/dal/algo/decision_forest/test/best_first_leaf_selection.cpp— a 10-point toy case where the buggy vs. fixed formula disagree on accepting the root's only candidate split. Verified it fails on pre-fix code.