[英]I want to plot my data and color depen on cluster
I need to plot my k means algorithm in python but I don't understand how to plot it I want to plot it and the color is depend on their cluster, I need to plot my k means algorithm in python but I don't understand how to plot it I want to plot it and the color is depend on their cluster,
I tried several code in the internet but I don't understand it and my x and y co-ordinates are sum[0] and sum[1] and my index for clustering is in centBaru variable.我在互联网上尝试了几个代码,但我不明白,我的 x 和 y 坐标是 sum[0] 和 sum[1],我的聚类索引在 centBaru 变量中。
sum[0]=[30000,50000,50000,4000,......]
sum[1]=[0.333333,0.12121,0.232,0.1212211,......]
centBaru=contain index cluster
I want the output like when I use library sklearn.我想要 output 就像我使用库 sklearn 时一样。
'plt.scatter(df['x'], df['y'], c= kmeans.labels_.astype(float), s=50, alpha=0.5)
import matplotlib.pyplot as plt
%matplotlib inline
s['x']: [30000,50000,50000,4000]
s['y']: [0.333333,0.12121,0.232,0.1212211]
s['centBaru']: [0,2,1,1] # id of claster for each point
# so first point would be (x,y) = (30000, 0.33333) with color Red (i.e. id of cluster = "0"
cl = ['r','g','b'] # colors for different clusters
plt.scatter(x = s['x'],y = s['y'], c = [cl[x] for x in s['centBaru']])
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.