简体   繁体   中英

What is meant by the term ‘random-state’ in 'KMeans' function in package 'sklearn.cluster' in python

What is meant by "random-state" in python KMeans function? I tried to find out from Google and referred https://scikit-learn.org/stable/modules/generated/sklearn.cluster.KMeans.html but I could not find a precise answer.

A gotcha with the k-means alogrithm is that it is not optimal. That means, it is not sure to find the best solution, as the problem is not convex (for the optimisation).

You may be stuck into local minima, and hence the result of your algorithm depends of your initialization (of your centroids). A good practice in order to find a good minimum is to rerun the algortihm several times with several initializations and keep the best result.

As stated by the others, random_state makes the results reproducible and can be useful for debugging

Bear in mind that the KMeans function is stochastic (the results may vary even if you run the function with the same inputs' values). Hence, in order to make the results reproducible, you can specify a value for the random_state parameter.

Random state in Kmeans function of sklearn mainly helps to

  1. Start with same random data point as centroid if you use Kmeans++ for initializing centroids.
  2. Start with same K random data points as centroid if you use random initialization.

This helps when one wants to reproduce results at some later point in time.

random_state : int, RandomState instance or None, optional, default: None If int, random_state is the seed used by the random number generator; If RandomState instance, random_state is the random number generator; If None, the random number generator is the RandomState instance used by np.random.

See: http://scikit-learn.org/stable/modules/generated/sklearn.cluster.KMeans.html

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