1 3D聚类和普通的二维聚类实质一样,只不过维数太高了,用三维图来表示了.

下面将官网的改成只生成一个图了

#!/usr/bin/python
# -*- coding:utf-8 -*- print(__doc__) # Code source: Gaël Varoquaux
# Modified for documentation by Jaques Grobler
# License: BSD 3 clause import numpy as np
import matplotlib.pyplot as plt
# Though the following import is not directly being used, it is required
# for 3D projection to work
from mpl_toolkits.mplot3d import Axes3D from sklearn.cluster import KMeans
from sklearn import datasets np.random.seed(5) iris = datasets.load_iris()
X = iris.data
y = iris.target estimators = [('k_means_iris_8', KMeans(n_clusters=8)),
('k_means_iris_3', KMeans(n_clusters=3)),
('k_means_iris_bad_init', KMeans(n_clusters=3, n_init=1,
init='random'))] fignum = 1
titles = ['8 clusters', '3 clusters', '3 clusters, bad initialization']
# for name, est in estimators:
name = 'k_means_iris_8'
est = KMeans(n_clusters=8)
print(est)
picture = plt.figure(fignum, figsize=(4, 3))
ax = Axes3D(picture, rect=[0, 0, .95, 1], elev=48, azim=134)
est.fit(X)
labels = est.labels_ ax.scatter(X[:, 3], X[:, 0], X[:, 2],
c=labels.astype(np.float), edgecolor='k') ax.w_xaxis.set_ticklabels([])
ax.w_yaxis.set_ticklabels([])
ax.w_zaxis.set_ticklabels([])
ax.set_xlabel('Petal width')
ax.set_ylabel('Sepal length')
ax.set_zlabel('Petal length')
ax.set_title(titles[fignum - 1])
ax.dist = 12 # Plot the ground truth
picture = plt.figure(fignum, figsize=(4, 3))
ax = Axes3D(picture, rect=[0, 0, .95, 1], elev=48, azim=134) for name, label in [('Setosa', 0),
('Versicolour', 1),
('Virginica', 2)]:
ax.text3D(X[y == label, 3].mean(),
X[y == label, 0].mean(),
X[y == label, 2].mean() + 2, name,
horizontalalignment='center',
bbox=dict(alpha=.2, edgecolor='w', facecolor='w'))
# Reorder the labels to have colors matching the cluster results
y = np.choose(y, [1, 2, 0]).astype(np.float)
ax.scatter(X[:, 3], X[:, 0], X[:, 2], c=y, edgecolor='k') ax.w_xaxis.set_ticklabels([])
ax.w_yaxis.set_ticklabels([])
ax.w_zaxis.set_ticklabels([])
ax.set_xlabel('Petal width')
ax.set_ylabel('Sepal length')
ax.set_zlabel('Petal length')
ax.set_title('Ground Truth')
ax.dist = 12 plt.show()

官网链接:https://scikit-learn.org/stable/auto_examples/cluster/plot_cluster_iris.html#sphx-glr-auto-examples-cluster-plot-cluster-iris-py

参考:https://mp.weixin.qq.com/s?__biz=MzAxNTc0Mjg0Mg==&mid=2653290530&idx=1&sn=7008fc46129106703a05fdfef1ddd4e6&chksm=802dc237b75a4b2173af42e9703c8591e3a4a37e50b2825f5a00cdba1099b49297f2300169e6&mpshare=1&scene=1&srcid=10178eaFgbBY6JZo05vM66s1&sharer_sharetime=1571301323063&sharer_shareid=a49b9557eabaed0d06d2de311dd63b54&pass_ticket=9rhsUGDoFYNdc2RJMbTG%2BMUeXE%2BY%2Bb9d2F3ZAMul8kAKgV7h8aQNp4StajH8jKTj#rd

最新文章

  1. 关于xml的使用。
  2. iOS NSOperation 封装 通知实现界面更新
  3. hdu4508 完全背包,湫湫系列故事——减肥记I
  4. robotframework 测试工具添加PDF文件内容匹配插件
  5. 筛选DataTable数据的方法
  6. EntityFrameowk6.1 使用enum和低版本的不同
  7. java.net.SocketException: Broken pipe 异常可能的原因
  8. 开发步骤Dubbo、spring mvc、springboot、SSM开发步骤
  9. 理解DNS
  10. nginx启动停止
  11. 58 同城 iOS 客户端 iOS11 及 iPhone X 适配实践
  12. iOS编程中的音频知识(二):那么多种格式我应该用哪一个?
  13. BZOJ_3585_mex && BZOJ_3339_Rmq Problem_莫队+分块
  14. Nginx upstream变量
  15. Python 获取文件中最长行的长度和最长行
  16. make、makefile、cmake、qmake对比
  17. 【数论】Prime Time UVA - 10200 大素数 Miller Robin 模板
  18. qt 提高图片加载速度
  19. VS 编译后 install报错(error MSB3073)
  20. css3 2D转换(2D Transform) 动画(Animation)

热门文章

  1. 新手 vim常用命令总结 (转)
  2. Node.js 最早 npm 包 request 将被废弃
  3. windows设置通过NFS连接到Linux共享数据
  4. neutron网络服务部署
  5. 牛客练习赛26 D xor序列 (线性基)
  6. react-native启动时红屏报错:Unable to load script.Make sure you're either running a metro server or that ....
  7. open函数的打开标志所在文件
  8. java课堂动手测试
  9. 判断request中是否有文件
  10. JAVA笔记16-生产者消费者问题