k-means 算法
来源:互联网 发布:京东联盟和淘宝联盟 编辑:程序博客网 时间:2024/06/05 14:14
from numpy import concatenate,column_stack,row_stackimport numpy as npimport matplotlib.pyplot as plt#%matplotlib inlinefrom sklearn.datasets.samples_generator import make_blobs# X为样本特征,Y为样本簇类别, 共1000个样本,每个样本4个特征,共4个簇,簇中心在[-1,-1], [0,0],[1,1], [2,2], 簇方差分别为[0.4, 0.2, 0.2]X, y = make_blobs(n_samples=1000, centers=[[-1,-1], [0,0], [1,1]] ,cluster_std=[0.4, 0.2, 0.2], random_state =9)plt.scatter(X[:, 0], X[:, 1], marker='o')plt.show()from sklearn.cluster import KMeansy_pred = KMeans(n_clusters=3, random_state=9).fit_predict(X)plt.scatter(X[:, 0], X[:, 1], c=y_pred)plt.show()from sklearn import metricsprint(metrics.calinski_harabaz_score(X, y_pred)) yy=np.array([y_pred])un=np.hstack((X,yy.T))print(un)print('\n')A_1=['0','0','0']A_2=['1','1','1']A_3=['2','2','2']for i in range(yy.shape[1]): if un[i][2]==0: A_1=row_stack((A_1,un[i])) elif un[i][2]==1: A_2=row_stack((A_2,un[i])) elif un[i][2]==2: A_3=row_stack((A_3,un[i])) print(A_1,'\n','A_1 have ',A_1.shape[0],'element') print(A_2,'\n','A_2 have ',A_2.shape[0],'element') print(A_3,'\n','A_3 have ',A_3.shape[0],'element')
阅读全文
0 0
- K-means算法补充:K-means++
- k-means算法
- K-MEANS算法
- K-MEANS算法
- K-means算法
- k-means算法
- K-Means 算法
- K-Means 算法
- 深入浅出K-Means算法
- 聚类:K-means算法
- K-Means 算法
- k-means 算法
- 深入浅出K-Means算法
- K-Means 算法
- 深入浅出K-means算法
- 深入浅出K-Means算法
- k means算法入门
- K-means算法
- pom.xml文件报错
- 预计华为Mate10比小米Mix2强大好几倍,一起来看看它“强大的”短信误删恢复功能吧
- 手机端页面自适应解决方案—rem布局
- array 方法
- ZeroMQ 原理及其优点
- k-means 算法
- 笨办法学 Python · 续 练习 9:`sed`
- ubuntu 14.04+opencv+opencv_contrib-3.1.0编译安装
- Cannot switch on a value of type String for source level below 1.7. Only convertible int values or e
- ubuntu卸载某个package失败的处理方法
- 信息论基础
- 2017 Multi-University Training Contest 4 1003 || HDU6069
- 使用jQuery实现点击左右滑动切换特效
- 使用java写一个hello world