本文整理汇总了Python中sklearn.cluster.AgglomerativeClustering.set_params方法的典型用法代码示例。如果您正苦于以下问题:Python AgglomerativeClustering.set_params方法的具体用法?Python AgglomerativeClustering.set_params怎么用?Python AgglomerativeClustering.set_params使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类sklearn.cluster.AgglomerativeClustering
的用法示例。
在下文中一共展示了AgglomerativeClustering.set_params方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: outlier_clusters_ward
# 需要导入模块: from sklearn.cluster import AgglomerativeClustering [as 别名]
# 或者: from sklearn.cluster.AgglomerativeClustering import set_params [as 别名]
def outlier_clusters_ward(x, y, skill=None, memory=None):
# TODO: incorporate skill
data = np.vstack((x, y)).T
if len(data) == 0:
# uh.
print 'clustering: NO cluster members!'
cluster_centers = np.array([[-1, -1]])
cluster_labels = []
labels = []
n_clusters = 0
dist_within = np.array([])
elif len(data) == 1:
print 'clustering: only 1 data point!'
cluster_centers = data
cluster_labels = [0]
labels = np.array([0])
n_clusters = 1
dist_within = np.array([0])
else:
dist_within = 1000
dist_max = 75
n_clusters = 0
n_clusters_max = 10
clusterer = AgglomerativeClustering(n_clusters=n_clusters,
memory=memory)
# while dist_within > dist_max, keep adding clusters
while (dist_within > dist_max) * (n_clusters < n_clusters_max):
# iterate n_clusters
n_clusters += 1
clusterer.set_params(n_clusters=n_clusters)
# cluster
labels = clusterer.fit_predict(data)
# get cluster_centers
cluster_labels = range(n_clusters)
cluster_centers = np.array([np.mean(data[labels == i], axis=0)
for i in cluster_labels])
# find dist_within: the maximum pairwise distance inside a cluster
dist_within = np.max([np.max(pairwise_distances(
data[labels == i]))
for i in cluster_labels])
dist_within_final = np.array([np.max(pairwise_distances(
data[labels == i])) for i in cluster_labels])
return cluster_centers, cluster_labels, labels, n_clusters, dist_within_final