FIX IndexError due to imprecision in KMeans++
@@ -107,6 +107,9 @@ def _k_init(X, n_clusters, x_squared_norms, random_state, n_local_trials=None):
rand_vals = random_state.random_sample(n_local_trials) * current_pot
candidate_ids = np.searchsorted(stable_cumsum(closest_dist_sq),
rand_vals)
+ # XXX: numerical imprecision can result in a candidate_id out of range
+ np.clip(candidate_ids, None, closest_dist_sq.size - 1,
+ out=candidate_ids)
# Compute distances to center candidates
distance_to_candidates = euclidean_distances(
