设 x1,x2,…,xn x_1, x_2, \dots, x_nx
1
,x
2
,…,x
n
组成数据点集合,这里并不需要假设数据集的结构。令 s ss 是一个量化任何两点相似度的函数。对任意 xi x_ix
i
, s(xi,xj)>s(xi,xk) s(x_i, x_j)>s(x_i, x_k)s(x
i
,x
j
)>s(x
i
,x
k
), 当且仅当
xi x_ix
i
与 xj x_jx
j
更相似。在这里,使用负平方距离,即,
# #############################################################################
# Plot result
import matplotlib.pyplot as plt
from itertools import cycle
plt.close('all')
plt.figure(1)
plt.clf()
colors = cycle('bgrcmykbgrcmykbgrcmykbgrcmyk')
for k, col in zip(range(n_clusters_), colors):
class_members = labels == k
cluster_center = X[cluster_centers_indices[k]]
plt.plot(X[class_members, 0], X[class_members, 1], col + '.')
plt.plot(cluster_center[0], cluster_center[1], 'o', markerfacecolor=col,
markeredgecolor='k', markersize=14)
for x in X[class_members]:
plt.plot([cluster_center[0], x[0]], [cluster_center[1], x[1]], col)
plt.title('Estimated number of clusters: %d' % n_clusters_)
plt.show()