kmeans.py 文件源码

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

项目:ref-extract 作者: brandonrobertz 项目源码 文件源码
def closest_label(X, labels, vec, dist='cosine', ooc_only=False, top=10):
    if dist == 'euclidean':
        sim = euclidean_distances(X, vec.reshape(1, -1))
    elif dist == 'cosine':
        sim = cosine_similarity(X, vec.reshape(1, -1))
    else:
        raise NotImplementedError('dist must be euclidean or cosine')
    # get the top five indices
    indices = sim.argsort(axis=0)[-top:][::-1]
    words = []
    for i in indices:
        words.append(labels[i[0]])
    return " ".join(words)
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号