Skip to main content

best_split

Function best_split 

Source
fn best_split(
    samples: &[(TreeSample, f64)],
    min_samples_leaf: usize,
    sse: f64,
    min_rel_var_reduction: f64,
) -> Option<(u8, u64)>
Expand description

Search the best binary split for a node’s samples.

For each feature, the samples are sorted by the feature value and the midpoints between distinct values are swept in order. The left group accumulates the weighted label sum and sum-of-squares so the weighted SSE of both groups is O(1) per candidate. Both groups must meet min_samples_leaf (a sample count, unchanged by the recency weighting) and the split must remove at least min_rel_var_reduction * sse. The first maximum-reduction split wins, so ties resolve to the smallest threshold that reaches the reduction.

Returns (feature, threshold).