similar_posts.py 文件源码

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

项目:hugo_similar_posts 作者: elbaulp 项目源码 文件源码
def elbowMethod(X, k=21):
    distortions = []
    for i in range(1, k):
        km2 = KMeans(n_clusters=i,
                     init='k-means++',
                     n_init=10,
                     random_state=0,
                     n_jobs=-1,
                     verbose=0)
        km2.fit(X)
        distortions.append(km2.inertia_)
        print('k=%s, Distortion: %.2f' % (i, km2.inertia_))

    plt.plot(range(1, k), distortions, marker='o')
    plt.xlabel('Number of clusters')
    plt.ylabel('Distortion')
    plt.show()
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号