摘要:
import matplotlib.pyplot as plt import numpy as np from sklearn.datasets import load_iris iris=load_iris() X=iris.data print(X) from sklearn.cluster import KMeans est=KMeans(n_clusters=3) est.fit(... 阅读全文
摘要:
1.用python实现K均值算法import numpy as np x=np.random.randint(1,100,[20,1]) y=np.zeros(20) k=3 def initcenter(x,k): return x[:k] kc=initcenter(x,k) kc def nearest(kc,i): d=(abs(kc-i)) w=... 阅读全文
摘要:
import numpy as np from sklearn.datasets import load_iris iris=load_iris() x=iris.data[:,1] y=np.zeros(150) def initcent(x,k): #初始聚类中心数组 return x[0:k].reshape(k) def nearest(kc,i): #数组中的值,... 阅读全文