摘要: 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(... 阅读全文
posted @ 2018-10-25 20:28 zhongwolin 阅读(4632) 评论(0) 推荐(0) 编辑
摘要: 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=... 阅读全文
posted @ 2018-10-25 17:05 zhongwolin 阅读(5266) 评论(0) 推荐(0) 编辑
摘要: 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): #数组中的值,... 阅读全文
posted @ 2018-10-25 16:22 zhongwolin 阅读(1107) 评论(0) 推荐(0) 编辑