简体   繁体   中英

Initialization of the kmeans2 in python

I am using scipy.cluster.vq.kmeans2 which, by definition, initializes the K-means randomly (given the pre-defined initialization method - random, points).

Is there a way to make the initialization stable, ie, for the same initial centroids to obtain the same clustering results, but without using minit='matrix' ? I really don't know what the initial point are but I want them to be the same for all simulations runs (eg for reproducible outputs).

You can seed the default numpy random number generator, for example:

from numpy import random
random.seed(123)

as shown in the last example here (which seems to be applicable to kmeans2 as well).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM