from scipy.cluster.hierarchy import dendrogram, linkage,fcluster
import numpy as np
import matplotlib.pyplot as plt
# data
np.random.seed(4711) # for repeatability of this tutorial
a = np.random.multivariate_normal([10, 0], [[3, 1], [1, 4]], size=[100,])
b = np.random.multivariate_normal([0, 20], [[3, 1], [1, 4]], size=[50,])
X = np.concatenate((a, b),)
plt.scatter(X[:,0], X[:,1])
^{pr2}$
max_d = 50
clusters = fcluster(Z, max_d, criterion='distance')
# now if I have new data
a = np.random.multivariate_normal([10, 0], [[3, 1], [1, 4]], size=[10,])
b = np.random.multivariate_normal([0, 20], [[3, 1], [1, 4]], size=[5,])
X_test = np.concatenate((a, b),)
print(X_test.shape) # 150 samples with 2 dimensions
plt.scatter(X_test[:,0], X_test[:,1])
plt.show()
如何计算新数据的距离并使用训练数据中的簇来分配簇?在
博客展示了使用Python进行分层聚类的代码,通过生成随机数据进行聚类操作。还提出了如何计算新数据的距离,并使用训练数据中的簇来分配簇的问题,涉及到分层聚类和新数据处理。
33

被折叠的 条评论
为什么被折叠?



