本文整理汇总了Python中sklearn.cluster.KMeans.append方法的典型用法代码示例。如果您正苦于以下问题:Python KMeans.append方法的具体用法?Python KMeans.append怎么用?Python KMeans.append使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类sklearn.cluster.KMeans
的用法示例。
在下文中一共展示了KMeans.append方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: find_labels
# 需要导入模块: from sklearn.cluster import KMeans [as 别名]
# 或者: from sklearn.cluster.KMeans import append [as 别名]
def find_labels(method, n_clusters, data):
if method == 'KMeans':
labels = KMeans(n_clusters=n_clusters).fit_predict(data)
elif method == 'NaiveKMeans':
labels = []
dist_matrix, centers_idxs = cluster_centers(data, n_clusters)
for idx, point in enumerate(data):
labels.append(np.argmin([dist_matrix[idx, c_idx] for c_idx in centers_idxs]))
elif method == 'Spread':
labels = []
dist_matrix, centers_idxs = spread_centers(data, n_clusters)
for idx, point in enumerate(data):
labels.append(np.argmin([dist_matrix[idx, c_idx] for c_idx in centers_idxs]))
elif method == 'KMeansGram3':
labels = KMeans(n_clusters=n_clusters).fit_predict(data.T)
elif method == 'HarmonyBaskets':
coeff = find_harmony_coeff(data)
labels = KMeans(n_clusters=n_clusters).fit_predict(coeff[:, np.newaxis])
else:
raise Exception('Method not recognized')
return np.array(labels)