kmeans_st#

kmeans_st(data, clusters, restarts=0, *, random_state=0, max_iter=50)#

Partition rows with EEGLAB’s Hartigan-Wong k-means.

The first pass builds centroids from a UPGMA cut and does not draw random numbers. Restarts draw a NumPy permutation from random_state, not MATLAB randperm, so restart membership is reproducible here and not comparable to EEGLAB. Labels are zero-based indices of the centroid rows from the kept start.

Parameters:
  • data (Any) – Two-dimensional observation matrix.

  • clusters (int) – Number of clusters. At least two.

  • restarts (int) – Extra random starts after the UPGMA pass. A better solution resets the remaining count.

  • random_state (int) – Seed for restart permutations.

  • max_iter (int) – Maximum transfer passes per start.

Returns:

Centroids, labels, and total squared error.

Return type:

tuple[ndarray, ndarray, float]