python sklearn使用kmeans对鸢尾花进行分类(简单实现)

from sklearn.cluster import KMeans as k
import matplotlib.pyplot as plt
from sklearn.datasets import  load_iris#导入数据
from mpl_toolkits.mplot3d import Axes3D#3d图
import numpy as np
import sklearn as s
iris=load_iris()
a=iris.data
b=iris.target
est = k(n_clusters=3)#分成三类
est.fit(a)#拟合
l=est.labels_
X=a
#print(l)
fig = plt.figure(1, figsize=(4, 3))#图纸长四宽二
ax = Axes3D(fig, rect=[0, 0, .95, 1], elev=49, azim=140)
ax.scatter(X[:, 3], X[:, 0], X[:, 2],c=l.astype(np.float), edgecolor='k')
plt.show()
![结果如图](https://img-blog.csdnimg.cn/2021060611054913.PNG?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L20wXzQ5MDQwNzU1,size_16,color_FFFFFF,t_70#pic_center)





猜你喜欢

转载自blog.csdn.net/m0_49040755/article/details/117621692
今日推荐