← 返回题库
初级

第14章 聚类方法 - k均值聚类 - 可视化

未完成
初级参考 完整示例代码供参考,建议自己理解后重新输入
import numpy as np
import matplotlib.pyplot as plt
from sklearn.cluster import KMeans

x = np.random.rand(100, 2)
kmeans = KMeans(n_clusters=3, random_state=0).fit(x)
labels = kmeans.labels_

plt.scatter(x[:, 0], x[:, 1], c=labels)
plt.scatter(kmeans.cluster_centers_[:, 0], kmeans.cluster_centers_[:, 1], c='red', marker='x', s=200)
Python 代码 🔒 登录后使用
🔒

登录后即可练习

注册免费账号,在浏览器中直接运行 Python 代码