
上QQ阅读APP看书,第一时间看更新
3 – The k-means clustering algorithm
sklearn now does the job using the training dataset and hyperparameters in the following lines of code:
#III.k-means clustering algorithm
kmeans = kmeans.fit(dataset) #Computing k-means clustering
The gcenter array contains the geometric centers or centroids and can be printed for verification purposes, as shown in this snippet:
gcenters = kmeans.cluster_centers_
print("The geometric centers or centroids:"
print(gcenters)
'''Ouput of centroid coordinates
[[ 48.7986755 85.76688742]
[ 32.12590799 54.84866828]
[ 96.06151645 84.57939914]
[ 68.84578885 55.63226572]
[ 48.44532803 24.4333996 ]
[ 21.38965517 15.04597701]]
'''
These geometric centers need to be visualized with labels for decision-making purposes.