简体   繁体   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, 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']])

it gives you result like this:它给你这样的结果: 在此处输入图像描述

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 plot序列数据,如何根据簇改变颜色 - How to plot sequential data, changing the color according to cluster 如何将模型中带有颜色的数据绘制到matplotlib底图上? 为什么没有显示数据? - How do I plot data with color from my model onto matplotlib Basemap? Why is data not showing up? 我想在2个日期的同一点绘制数据 - I want to plot data in the same point of 2 dates 想要为每个盆栽簇涂上不同的颜色 - Want to Color Each Potted Cluster a Different Color 如何让x轴只显示我想绘制的数据? 而不是包括没有情节的标签? - How do i get the x axis to only show my data i want to plot? Instead of it including labels with no plots? 我的实际和预测的原始数据集有超过 5000 多个值我只想 plot 150 个值 - My orginal data set of actual and predicted has over 5000+ values i want to only plot 150 values 如何在 plotly (python) 中根据我的数据集中的“颜色”列更改散点图点的颜色? - How can I change the color of my scatter plot points based on a "color" column in my dataset in plotly (python)? 如何在我的 Mapper 和 Reducer 中使用此代码? 我想在 Google 集群中运行此代码 - How can i use this code in my Mapper and Reducer ? i want run this code in Google cluster 我想使用python boto3脚本将数据加载到Amazon Redshift集群中 - I want to load data into an Amazon Redshift Cluster using python boto3 script 如何将我的csv数据可视化为群集 - How can I visualize my csv data into cluster
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM