【问题标题】:plotting k-modes cluster in python在python中绘制k-modes集群
【发布时间】:2020-02-10 10:42:29
【问题描述】:

我有 10 个处于 k 模式的集群,

数据:- 分类(我转换为二进制然后运行模型)。

使用的技术:- jupyter-python。

疑问:- 1. 找到准确性。

  1. 在 2d 和 3d 中绘制/可视化集群。

【问题讨论】:

  • 你试过什么?没有任何代码 sn-p 或数据,很难推测您要做什么。

标签: python jupyter


【解决方案1】:

这样的事情应该是一个好的开始。

#recreate data to feed into the algorithm
data = np.asarray([np.asarray(df['field1']),np.asarray(df['field2'])]).T

So now running the following piece of code:

# computing K-Means with K = 5 (5 clusters)
centroids,_ = kmeans(data,5)
# assign each sample to a cluster
idx,_ = vq(data,centroids)

# some plotting using numpy's logical indexing
plot(data[idx==0,0],data[idx==0,1],'ob',
     data[idx==1,0],data[idx==1,1],'oy',
     data[idx==2,0],data[idx==2,1],'or',
     data[idx==3,0],data[idx==3,1],'og',
     data[idx==4,0],data[idx==4,1],'om')
plot(centroids[:,0],centroids[:,1],'sg',markersize=8)
show()

这是一个很好的资源。

https://www.pythonforfinance.net/2018/02/08/stock-clusters-using-k-means-algorithm-in-python/

【讨论】:

    猜你喜欢
    • 2018-10-10
    • 2017-06-09
    • 2017-08-10
    • 1970-01-01
    • 2017-07-28
    • 2018-02-24
    • 1970-01-01
    • 2021-12-13
    • 2019-06-10
    相关资源
    最近更新 更多