def get_cluster_threshold(weights):
estimator = KMeans(n_clusters = 2)
data = np.asarray(weights)
data = data.reshape(-1,1)
# print data
clusters_idx = estimator.fit_predict(data)
max_idx = data.argmax()
max_cluster = clusters_idx[max_idx]
#print max_cluster
low_cluster = []
if max_cluster == 1:
indices = np.argwhere(clusters_idx == 0)
for idx in indices:
low_cluster.append(data[idx])
threshold = max(low_cluster)
threshold = threshold[0][0]
else:
indices = np.argwhere(clusters_idx == 1)
for idx in indices:
low_cluster.append(data[idx])
threshold = max(low_cluster)
threshold = threshold[0][0]
# print threshold
return threshold
graphcluster.py 文件源码
python
阅读 17
收藏 0
点赞 0
评论 0
评论列表
文章目录