zoukankan      html  css  js  c++  java
  • 使用scipy进行聚类

    近期做图像的时候,突然有个idea,须要进行聚类,事实上算法非常easy,可是当时非常急。就直接使用了scipy的cluster。

    使用起来事实上非常easy,可是中文的文章非常少,所以就简单的介绍一下。感兴趣的也能够自己去看一下英文的文档:http://docs.scipy.org/doc/scipy/reference/cluster.html。

    这是我从stackoverflow看到的一个demo。假设仅仅是简单的使用cluster。这样就能够了。

    import scipy
    import scipy.cluster.hierarchy as sch
    import matplotlib.pylab as plt
    
    scipy.randn(100,2)
    
    d = sch.distance.pdist(X)
    
    Z= sch.linkage(d,method='complete')
    
    P =sch.dendrogram(Z)
    
    plt.savefig('plot_dendrogram.png')
    
    T = sch.fcluster(Z, 0.5*d.max(), 'distance')
    #array([4, 5, 3, 2, 2, 3, 5, 2, 2, 5, 2, 2, 2, 3, 2, 3, 2, 5, 4, 5, 2, 5, 2,
    #       3, 3, 3, 1, 3, 4, 2, 2, 4, 2, 4, 3, 3, 2, 5, 5, 5, 3, 2, 2, 2, 5, 4,
    #       2, 4, 2, 2, 5, 5, 1, 2, 3, 2, 2, 5, 4, 2, 5, 4, 3, 5, 4, 4, 2, 2, 2,
    #       4, 2, 5, 2, 2, 3, 3, 2, 4, 5, 3, 4, 4, 2, 1, 5, 4, 2, 2, 5, 5, 2, 2,
    #       5, 5, 5, 4, 3, 3, 2, 4], dtype=int32)
    
    sch.leaders(Z,T)

    假设想要了解很多其它一些的话,能够參考 http://nbviewer.ipython.org/github/herrfz/dataanalysis/blob/master/week4/clustering_example.ipynb

    这篇文章事实上写的已经很棒了。尽管文件我没有可以成功down下来。



  • 相关阅读:
    opensuse使用zypper安装软件
    补习系列(1)-springboot项目基础搭建课
    补习系列-springboot-使用assembly进行项目打包
    log4j2 使用纪要
    mongos-sharding连接池配置
    maven-代码风格检查工具
    mtools-你可能没用过的mongodb神器
    mongodb分布式集群搭建手记
    mongodb分片扩展架构
    mongodb副本集高可用架构
  • 原文地址:https://www.cnblogs.com/bhlsheji/p/5099844.html
Copyright © 2011-2022 走看看