Kmodes.py 文件源码

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

项目:pyspark-distributed-kmodes 作者: ThinkBigAnalytics 项目源码 文件源码
def _labels_cost(X, centroids):
    """Calculate labels and cost function given a matrix of points and
    a list of centroids for the k-modes algorithm.
    """

    X = check_array(X, dtype = "object")

    npoints = X.shape[0]
    cost = 0.
    labels = np.empty(npoints, dtype='int64')
    for ipoint, curpoint in enumerate(X):
        diss = matching_dissim(centroids, curpoint)
        clust = np.argmin(diss)
        labels[ipoint] = clust
        cost += diss[clust]

    return labels, cost
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号