Skip to content
Advertisement

How to print KMeans intiatial parameters?

I am using PyCharm to run Kmeans using Iris data.

from sklearn.datasets import load_iris

iris = load_iris()

from sklearn.cluster import KMeans

kmeans = KMeans()
print(kmeans)

When I run this, simply prints KMeans() But I would like it to print the following:

KMeans(n_clusters=8, *, init='k-means++', n_init=10, max_iter=300, tol=0.0001, precompute_distances='deprecated', verbose=0, random_state=None, copy_x=True, n_jobs='deprecated', algorithm='auto')

How can this be accomplished?

Advertisement

Answer

Simply run kmeans.get_params(). This will print out the parameters (default or custom) used while instantiating the function in a dictionary format.

Please refer this link for more information.

User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement