Search code examples
pythoncluster-analysis

k-prototypes with stable results


I am using k-prototypes from k modes package based on python. As K-means,[k-prototypes] exports different results every time.

In K-modes, we could set random_state for getting stable results, how can i do the same thing for k-prototypes?


Solution

  • In this function call, init parameter can be huang, cao and random:

    def k_prototypes_single(Xnum, Xcat, nnumattrs, ncatattrs, n_clusters, n_points,
                            max_iter, num_dissim, cat_dissim, gamma, init, init_no,
                            verbose, random_state):
    

    Changing it to anything but random might help.

    On the other hand, np.random.seed(42) might help as well, since most likely the author is using np.random()