agglomerative.py 文件源码

python
阅读 22 收藏 0 点赞 0 评论 0

项目:Python-Machine-Learning-Cookbook 作者: PacktPublishing 项目源码 文件源码
def perform_clustering(X, connectivity, title, num_clusters=3, linkage='ward'):
    plt.figure()
    model = AgglomerativeClustering(linkage=linkage, 
                    connectivity=connectivity, n_clusters=num_clusters)
    model.fit(X)

    # extract labels
    labels = model.labels_

    # specify marker shapes for different clusters
    markers = '.vx'

    for i, marker in zip(range(num_clusters), markers):
        # plot the points belong to the current cluster
        plt.scatter(X[labels==i, 0], X[labels==i, 1], s=50, 
                    marker=marker, color='k', facecolors='none')

    plt.title(title)
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号