
上QQ阅读APP看书,第一时间看更新
5 – Displaying the results – data points and clusters
To make sense to a team or management, the program now prepares to display the results as data points and clusters. The data will be represented as coordinates and the clusters as colors with a geometric center or centroid, as implemented in this code:
#V.Displaying the results : datapoints and clusters
y = 0
for x in labels:
plt.scatter(dataset.iloc[y,0], dataset.iloc[y,1],color=colors[x])
y+=1
for x in range(k):
lines = plt.plot(gcenters[x,0],gcenters[x,1],'kx')
title = ('No of clusters (k) = {}').format(k)
plt.title(title)
plt.xlabel('Distance')
plt.ylabel('Location')
plt.show()
The dataset is now ready to be analyzed. The data has been transformed into data points (Cartesian points) and clusters (the colors). The x points represent the geometric centers or centroids, as shown in the following screenshot:

Output (data point and clusters)