k-means with selected initial centers
The default behavior of KMeans
is to initialize the algorithm multiple times using different random centroids (i.e. the Forgy method). The number of random initializations is then controlled by the n_init=
parameter (docs):
n_init : int, default: 10
Number of time the k-means algorithm will be run with different centroid seeds. The final results will be the best output of
n_init
consecutive runs in terms of inertia.
If you pass an array as the init=
argument then only a single initialization will be performed using the centroids explicitly specified in the array. You are getting a RuntimeWarning
because you are still passing the default value of n_init=10
(here are the relevant lines of source code).
It's actually totally fine to ignore this warning, but you can make it go away completely by passing n_init=1
if your init=
parameter is an array.