zoukankan      html  css  js  c++  java
  • 知道聚类图的绘制及中心的绘制,真的很重要

    from sklearn.datasets import make_blobs
    import matplotlib.pyplot as plt
    import numpy as np
    from sklearn.cluster import KMeans
    from sklearn import metrics
    from sklearn import datasets
    
    blobs, ground_truth = datasets.make_blobs(1000, centers=3,cluster_std=1.75)
    
    
    #先看看数据长什么样子
    f, ax = plt.subplots(figsize=(7, 5))
    colors = ['r', 'g', 'b']
    for i in range(3):
        p = blobs[ground_truth == i]
        ax.scatter(p[:,0], p[:,1], c=colors[i],label="Cluster {}".format(i))
    ax.set_title("Cluster With Ground Truth")
    ax.legend()
    f.show()
    f.savefig("9485OS_03-16")
    
    
    #绘制聚簇中心
    kmeans = KMeans(n_clusters=3)
    kmeans.fit(blobs)
    print(kmeans.cluster_centers_)
    
    f, ax = plt.subplots(figsize=(7, 5))
    colors = ['r', 'g', 'b']
    for i in range(3):
        p = blobs[ground_truth == i]
        ax.scatter(p[:,0], p[:,1], c=colors[i],label="Cluster {}".format(i))
        ax.scatter(kmeans.cluster_centers_[:, 0],kmeans.cluster_centers_[:, 1], s=100, color='black',label='Centers')
    ax.set_title("Cluster With Ground Truth")
    ax.legend()
    f.savefig("9485OS_03-17")
    f.show()

  • 相关阅读:
    引用类型构造器
    正则指引量词
    Ajax的XMLHttpRequest对象
    正则指引字符组
    方法可变数量的参数
    不使用XMLHttpRequest实现异步加载:Iframe和script
    可选参数、命名参数
    常量和字段
    正则指引括号
    值类型实例构造器
  • 原文地址:https://www.cnblogs.com/qqhfeng/p/5333057.html
Copyright © 2011-2022 走看看