Repository navigation
Description
Fell out of the #205 diagnosis. Not a benchmark-agreement question; a forest-quality one.
The observation
From the per-tree diagnostics added in #402, on Digits test data at the same mean top-vote fraction:
| unanimous predictions | |
|---|---|
| Flow | 25.3% |
| sklearn | 19.7% |
A forest that agrees with itself more often has trees that are more correlated with each other. Bagging exists to reduce variance by averaging over decorrelated estimators, so higher correlation means less of that benefit than the ensemble size suggests.
Flow currently scores higher on this row (0.955555558 against 0.936111111), so this is not a defect showing up as lost accuracy today. It is a structural property worth understanding, and it would matter more on harder data or with fewer trees.
Where the correlation could come from
In rough order of how much I would suspect each:
- Feature subsampling. Check how many features are drawn per split and whether the draw is per-node or per-tree. sklearn's default for classifiers is
sqrt(n_features)per split. If Flow draws more, or draws once per tree, trees see more of the same information and correlate. - Tie-breaking. Reduce Digits DecisionTree predictive disparity and compare learned tree structure #204 established that Flow takes the lowest feature index among exactly-tied candidates while sklearn takes the first from a random permutation, and that 68 of 122 split nodes on digits have multiple features at the exact f32 minimum. A deterministic tie-break is a systematic bias shared by every tree in the forest, which is precisely the kind of thing that correlates them. This is the most interesting candidate because it is a direct consequence of a rule we deliberately kept.
- Bootstrap sampling. The per-tree bootstrap unique-sample fraction is already emitted; compare it against sklearn's expected ~63.2%.
- Tree depth or stopping rules producing more similar structures.
Suggested approach
Measure before changing anything. The diagnostics needed are already emitted per #402: per-tree node and leaf counts, depths, root splits, bootstrap checksums and unique fractions, vote margins. Compare the distribution of root split features across the 10 trees on both sides. If Flow's trees share a root feature far more often than sklearn's, candidate 1 or 2 is confirmed and which one follows from whether the shared features are tied.
If it turns out to be the tie-break, note the tension: #204 and #426 deliberately kept and pinned the lowest-index rule, and tests/test_tree_split_tiebreak.flow enforces it. Randomising ties inside the forest builder only, leaving the single-tree builder deterministic, may be the right resolution, but that is a design decision worth stating explicitly rather than slipping in.
What would count as done
Either an explanation of the correlation with numbers, or a change that reduces it with the effect on the canonical RandomForest row reported both ways. Do not chase the accuracy number; Flow is already ahead there. The question is whether the ensemble is doing what an ensemble is supposed to do.
Activity
godofecht commentedon Aug 20, 2026
Measured: the premise does not hold. Flow's trees are less correlated than sklearn's.
I measured tree correlation directly rather than through the unanimity proxy. On the
canonical row (digits, 10 trees,
max_depth=10, seed 42, standard-scaled, canonicalfixture split) Flow's forest is less correlated than sklearn's on every direct
measure, while being more unanimous.
Unanimity and correlation move in opposite directions here, so unanimity is not
serving as a correlation measure.
Direct correlation, both sides, same environment
Mean per-tree accuracy is the same to within 0.0014, so the two forests are built
from equally strong trees and the correlation numbers are directly comparable.
Flow's agreement in excess of independence is 0.0489 against sklearn's 0.0550, and
kappa is 0.1154 against 0.1292. Flow is roughly 11% less correlated.
Note on the sklearn unanimity figure: locally I measure 0.205556 where the committed
sklearn_results_v2.txthas 0.197222. Per-tree node counts match the committed fileexactly, so the trees are identical and the 3-row difference is a platform artifact
in
StandardScaleroutput, not a modelling difference. Both figures sit well belowFlow's 0.253 and the conclusion is unchanged.
Why unanimity is higher despite lower correlation
Decomposing pairwise agreement into its four outcomes:
Correlated error is the quantity bagging is meant to suppress, and Flow has 20% less
of it (0.0212 against 0.0265). sklearn's higher total agreement is concentrated
entirely in trees being wrong the same way.
Every unanimous prediction is correct on both sides. Flow's extra unanimity is 91
test rows where all ten trees are right against sklearn's 74. That is a strength
signal about easy examples. Flow's distinct-label histogram also has more mass in
the tail (2 rows split 7 ways; sklearn's maximum is 6), so Flow is simultaneously
more decisive on easy rows and more diverse on hard ones. That is the profile you
want from an ensemble, and it is consistent with Flow's higher forest accuracy at
equal tree strength.
Candidates 1, 3 and 4: checked, all clear
1. Feature subsampling.
lib/scikit/ensemble.flow:43-45setsmax_features = floor(sqrt(n_features))= 8 for digits, matching sklearn's classifierdefault. The draw happens per node inside
_build_classifier_tree_rf(
lib/scikit/tree.flow:951-965), not per tree. This matches sklearn.I also checked the PRNG itself, since a biased draw would look identical to a biased
tie-break. Simulating
prng_int(p, 64)(which reduces to the low 6 bits ofxorshift32) over 200k nodes gives quadrant shares 0.2502 / 0.2501 / 0.2497 / 0.2500
and mean drawn index 31.4955 against a uniform 31.5. The draw is clean.
3. Bootstrap sampling. For n=1437 the theoretical unique fraction is 0.63225,
with sd 0.00822 per tree and 0.00260 for a mean of ten. Flow's mean is 0.62867
(1.38 sd low), sklearn's is 0.63549 (1.25 sd high). Both are inside noise. Flow's
sample is very slightly more duplicated, which decorrelates rather than correlates.
4. Depth and stopping. Every tree reaches depth 10 on both sides. Total internal
split nodes: Flow 1554, sklearn 1551. Per-tree node counts are Flow mean 311.8 sd
16.3 (range 291-339) against sklearn mean 311.2 sd 27.4 (range 271-353). Flow's trees
are more uniform in size, but as the table above shows this does not translate into
more correlated predictions.
The root-split test proposed in the issue comes back negative
Distinct root features across the 10 trees on digits:
53, 36, 38, 21, 33, 10, 21, 60, 58, 33= 8 distinct of 1021, 58, 33, 21, 42, 26, 34, 38, 58, 26= 7 distinct of 10Flow's roots are more diverse. This test does not detect the tie-break, because the
root sees 1437 samples and exact f32 ties in weighted Gini are rare there. The 68 of
122 tied nodes from #204 are concentrated in deep, small nodes.
Candidate 2: the tie-break is real, and it is a feature-usage bias
Looking at all internal nodes rather than just the roots, the deterministic rule is
clearly visible:
By feature quadrant (counts of splits):
Flow uses the first sixteen pixels 59% more often than sklearn and the last sixteen
37% less often, a monotone decline across the index range. sklearn sits near flat.
The cause is
lib/scikit/tree.flow:966: the candidate loop walksfeature_maskinascending index order, so among features tied at the exact f32 minimum the lowest
index always wins. sklearn scans its sampled features in Fisher-Yates order, so the
winner among ties is uniform over the tied set.
Ablation confirms causation
I changed only the scan order in
_build_classifier_tree_rf, recording the rejection-sampling draw order and iterating that instead of ascending index order. The set of
candidate features per node is untouched; only which tied feature wins changes.
One line of scan order closes about 85% of the feature-usage gap and lands the
quadrant profile almost exactly on sklearn's. The tie-break is confirmed as the sole
source of the low-index bias.
Two things follow that argue against making the change:
correlated errors from 0.0212 to 0.0245, both moving toward sklearn. Unanimity only
falls from 0.2528 to 0.2417, nowhere near sklearn's 0.2056.
So the deterministic tie-break is not the source of any correlation problem. On these
measurements it is mildly protective.
Recommendation: no change
I recommend closing this without a code change, for three reasons.
The stated defect is not present. Flow's trees are already less correlated than
sklearn's by every direct measure, and Flow's correlated-error rate is 20% lower.
Unanimity was standing in for correlation and it does not track it; the two move in
opposite directions across all three configurations measured above.
The tie-break bias is real and now quantified, but it is a feature-usage bias rather
than a correlation problem. It costs nothing on accuracy and removing it would move
three metrics the wrong way.
#204 and #426 pinned the lowest-index rule deliberately and
tests/test_tree_split_tiebreak.flowenforces it. Randomising ties inside the forestbuilder only would buy a feature-usage histogram closer to sklearn's, at the cost of
splitting the tie-break rule in two, weakening the property that test pins, and
slightly increasing tree correlation. That trade does not look worth taking on this
evidence.
The one residual difference worth recording for a future issue: sklearn's
BestSplitterkeeps drawing until it has evaluatedmax_featuresnon-constantfeatures, tracking
n_found_constantsandn_drawn_constants. Flow draws exactlymax_featuresfeatures and then skips constant columns(
lib/scikit/tree.flow:975-983), so it evaluates fewer real candidates per node. Ondigits many pixel columns are constant at a given node. This is the most likely
source of the ~15% of the feature-usage gap the tie-break ablation did not close. It
is a separate question from this issue and does not affect the correlation finding.
Reproduction
Diagnostics on both sides come from the #402 emitters plus a scratch harness computing
per-tree test predictions, pairwise agreement and its decomposition, and split-feature
histograms over all internal nodes. Flow-side numbers reproduce the committed
flow_results_v2.txtexactly (total internal splits 1554, per-tree node and leaf countsmatching); sklearn-side reproduces
sklearn_results_v2.txtnode counts exactly. Theharness was scratch-only and is not committed.
lib/scikit/tree.flowwas reverted afterthe ablation and the worktree is clean.
godofecht commentedon Aug 20, 2026
Closing. The premise of this issue is wrong, and I filed it on a misleading proxy.
I opened this off the unanimity figure alone: Flow unanimous on 25.3% of Digits predictions against sklearn's 19.7%, and inferred more correlated trees. Measuring correlation directly gives the opposite answer:
Tree strength is equal to within 0.0014, so those correlation figures are directly comparable. Flow's trees are about 11% less correlated, not more.
Why unanimity pointed the wrong way
Decomposing pairwise agreement: Flow's P(pair both wrong, same label) is 0.0212 against sklearn's 0.0265. Correlated error, the thing bagging exists to suppress, is 20% lower in Flow. sklearn's extra agreement is entirely trees being wrong the same way.
Unanimous-and-wrong is 0.000000 on both sides, so Flow's extra unanimity is 91 rows where all ten trees are right against sklearn's 74. Flow also carries more tail mass, with 2 rows splitting 7 ways where sklearn maxes at 6. Decisive on easy rows, diverse on hard ones, which is the good version of this.
Unanimity conflates "agrees because correct" with "agrees because correlated". It should not be read as a correlation proxy, and I should not have filed on it without the decomposition.
The tie-break is real, but it is not correlation
The root-split test I proposed comes back negative: Flow has 8 distinct roots of 10 against sklearn's 7, so Flow's roots are more diverse. The root sees 1437 samples where exact f32 ties are rare, so it cannot detect the tie-break at all.
Over all 1554 internal nodes the bias is clear: Flow's mean split feature index is 26.08 against sklearn's 32.04, and 63.96% of splits use a feature below index 32 against sklearn's 50.35%. That is a feature-usage bias from the lowest-index rule, confirmed by ablation. The PRNG was ruled out as an alternative explanation (simulating
prng_int(p, 64)over 200k nodes gives mean 31.4955 against a uniform 31.5).The ablation settles it against changing anything
Scanning in drawn order instead of ascending index moves the mean index 26.08 to 31.28 and the quadrant counts almost exactly onto sklearn's. But forest accuracy stays bit-identical at 0.955555558, and kappa rises 0.1154 to 0.1231 with correlated errors going 0.0212 to 0.0245.
Randomising ties makes correlation worse. So the change buys a prettier feature-usage histogram at the cost of the property this issue was opened to protect, while weakening
tests/test_tree_split_tiebreak.flowwhich #204 and #426 deliberately pinned.Candidates 1, 3 and 4 are cleared with numbers: drawn per node, correct; bootstrap unique fraction 0.62867 against a theoretical 0.63225, 1.38 sd, inside noise; all trees at depth 10, 1554 nodes against sklearn's 1551.
Closing as diagnosed, with no change. Two residuals worth pursuing separately are recorded below.