user3861925
user3861925

Reputation: 723

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, i.e., 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 (e.g. for reproducible outputs).

Upvotes: 1

Views: 474

Answers (1)

YS-L
YS-L

Reputation: 14738

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).

Upvotes: 2

Related Questions