fix(kmeans_init): score the best local trial with its own candidate in k-means++ #3859
All Vouch review confidence checks passed
Residual risk 0.18 = Change Risk (0.45) × (1 − Review Confidence (0.60)).
Review depth and reviewer attention state are adequate.
Model 1 · Change Risk (XGBoost)
Score: 0.45 · 450 lines diff across 5 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.366
Shallow Review Depth
shallow_review_depth
0.289
Real PR Conversation Timeline
1 comments
"Review active on #3859"
general
weight: 0.35
Vika-F
Description
k-means++ with local trials scored the previous best trial's slot with trial 0's candidate.
updateMinDistInBlockpassedpLastAddedCenter(trial 0) instead of&pLastAddedCenter[iBestTrial dim]for the best trial, in bothDataHelperDenseandDataHelperCSR.Whenever the previous round's best trial was not trial 0, that slot's candidate was never scored. Its potential came out equal to trial 0's, and the strict
<or last-bit rounding decided the pick. Results were still valid centers, but:sklearnex/cluster/tests/test_kmeans.py::test_dense_vs_sparse[dims2--k-means++]on the 2026.2 conda/pip VMs, which have no AVX2.The fix passes each trial's own candidate. The bug predates the move of the sources into
src/.Test. A white-box case in the private suite
test/internal.cpp(internal_tests, like knn's) callsDataHelperDenseandDataHelperCSR::updateMinDistInBlockdirectly. On 4 rows with integer coordinates and 3 trials, it runs the update once with each trial as the best and checks every trial's per-row distances and potential against hand-computed values. It covers dense and CSR, float32 and float64. Being private, it is not built against the release package, which ships neither the DAAL sources nor the backend interop headers. Without the fix it fails whenever the best trial is not trial 0.Validation.
kmeans_init:testsandkmeans:testspass on CPU in the dev link mode; the public suites also pass with--test_link_mode=release_static.plus_plus_denseis a separate implementation.Results of k-means++ init change wherever a non-zero trial won a round, on every ISA.
The GPU
Fatal Python error: Abortedfrom the same validation report is not addressed here. It needs a GPU repro.---
<details>
<summary>Checklist:</summary>
Completeness and readability
Testing
Performance
</details>
🤖 Generated with Claude Code