簡體   English   中英

我想 plot 我的數據和顏色取決於集群

[英]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,

我在互聯網上嘗試了幾個代碼,但我不明白,我的 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

我想要 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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM