# 提取字段并可视化数据,使用scatter plot f1 = data['V1'].values f2 = data['V2'].values X = np.array(list(zip(f1, f2))) # X = np.random.random((200, 2))*10 plt.scatter(X[:,0], X[:,1], c='black', s=6) 1. 2. 3. 4. 5. 6. # K-means里的K值 k = 3 # 随机...
plt.title("聚类图") plt.scatter(cla_x[0],cla_y[0],c = 'r',marker = 'h') plt.scatter(cla_x[1], cla_y[1], c='y', marker='.') plt.scatter(cla_x[2], cla_y[2], c='g', marker='o') plt.scatter(cla_x[3], cla_y[3], c='b', marker=',') plt.scatter(cla_x...
plt.plot(centerPoints[0][0], centerPoints[0][0], "b*") plt.plot(centerPoints[1][0], centerPoints[1][0], "b*") plt.scatter(cluster1[:,0], cluster1[:,1], c="r", alpha = 0.4) plt.scatter(cluster2[:,0], cluster2[:,1], c="g", alpha = 0.4) plt.savefig(str(count)...
scatter(clusters_centers[:, 0], clusters_centers[:, 1], s=90, c='r', marker='*') plt.title("KMeans clusters") plt.show() 4.2 噪声对聚类的影响 K-Means一个很大的缺陷就是对噪声或者离群点比较敏感,它无法区分出哪些是噪声或者离群点,只能给每一个数据点都判断出一个类别来,这样就会导致...
plt.plot(docs[:,0], docs[:,1], 'ko', label='line 3', linewidth=2) idx=0 for key,elems in centers.iteritems(): x,y=key pylab.scatter(x,y, marker=markers[idx], s = 500, linewidths=2,c=colors[idx]) for elem in elems: ...
scatter(point[0], point[1], c=('r' if cat == 0 else 'b')) predict = [[2, 1], [6, 9]] for feature in predict: cat = k_means.predict(predict) pyplot.show() 修改k值即可实现聚几类,不过只能实现1,2 更多类的聚类有待后续挖掘… 本文参与 腾讯云自媒体同步曝光计划,分享自作者个人...
iris=load_iris()X=iris.data[:,:2]print(X.shape)#150,2#plot data plt.figure()plt.scatter(X[:,0],X[:,1],c='blue',marker='o',label='point')plt.legend(loc=2)plt.show() 代码语言:javascript 代码运行次数:0 运行 AI代码解释 ...
result[1]48k_means = init_k_means(k=7)49result =K_means(data,seed_k,k_means)50print('Done')51#print(result[1])52print(count)53plt.figure(figsize=(8,8))54Color ='rbgyckm'55foriinrange(k):56mydata =np.array(result[0][i])57plt.scatter(mydata[:,0],mydata[:,1],color =...
kmeans.fit(data)labels = kmeans.labels_centroids = kmeans.cluster_centers_# 数据可视化plt.scatter(data[:, 0], data[:, 1], c=labels, cmap='viridis', marker='o')plt.scatter(centroids[:, 0], centroids[:, 1], c='red', marker='x')plt.xlabel('武功')plt.ylabel('内力')plt.title...
import plotly.graph_objs as godataPath = 'C:/Users/xzx/Desktop/linkHomeData.xlsx'data = pd.read_excel(dataPath,sheet_name='Sheet2')#Set marker propertiesmarkersize = data['geju']/3markercolor = data['zhuangxiu']#Make Plotly figurefig1 = go.Scatter3d(x=data['mianji'],y=data['chao...