本文整理汇总了Python中sklearn.cluster.KMeans.astype方法的典型用法代码示例。如果您正苦于以下问题:Python KMeans.astype方法的具体用法?Python KMeans.astype怎么用?Python KMeans.astype使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类sklearn.cluster.KMeans
的用法示例。
在下文中一共展示了KMeans.astype方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: KMeans
# 需要导入模块: from sklearn.cluster import KMeans [as 别名]
# 或者: from sklearn.cluster.KMeans import astype [as 别名]
0, ith_cluster_silhouette_values,
facecolor=color, edgecolor=color, alpha=0.7)
# Compute the new y_lower for next plot
y_lower = y_upper + 10 # 10 for the 0 samples
ax1.set_title("The silhouette plots")
# The vertical line for average silhoutte score of all the values
ax1.axvline(x=silhouette_avg, color="red", linestyle="--")
ax1.set_yticks([]) # Clear the yaxis labels / ticks
ax1.set_xticks([-0.1, 0, 0.2, 0.4, 0.6, 0.8, 1])
# 2nd Plot showing the actual clusters formed
colors = cm.spectral(y_pred.astype(float) / n_clusters)
ax2.scatter(X[:, 0], X[:, 1], marker='.', s=30, lw=0, alpha=0.7,
c=colors)
ax2.set_title("n = 2 Clusters")
ax2.xaxis.set_visible(False)
ax2.yaxis.set_visible(False)
y_pred = KMeans(n_clusters=3).fit_predict(X)
ax4 = fig.add_subplot(224)
silhouette_avg = silhouette_score(X, y_pred)
print("For n_clusters = 3 The average silhouette_score is :", silhouette_avg)
sample_silhouette_values = silhouette_samples(X, y_pred)
y_lower = 10
n_clusters = 3