Statistical-Learning-Method_Code icon indicating copy to clipboard operation
Statistical-Learning-Method_Code copied to clipboard

K means 簇中心更新的计算问题

Open FUTUREEEEEE opened this issue 4 years ago • 3 comments

def cal_groupcenter(group, Xarray):

    center = np.zeros(Xarray.shape[1])
    for i in range(Xarray.shape[1]): #range(4)
        for n in group:
            center[i] += Xarray[n][i]  #计算当前类中第i个特征的数据之和
    center = center / Xarray.shape[0]  #计算各个特征的均值
    return center

作者您好!十分感谢你开源的机器学习代码,受益良多,想请教一下:在上面的函数中,为什么使用center = center / Xarray.shape[0] (簇的和除以总样本个数),而不是center = center / len(group) 即每一簇的中心点的均值应该是该簇的和除以该簇的数目 代码位置如下⬇ 十分感激! https://github.com/Dod-o/Statistical-Learning-Method_Code/blob/01f6d6c9ebee258a61977137d3aadfcb5d997d04/Clustering/K-means_Clustering/K-means_Clustering.py#L101

FUTUREEEEEE avatar Nov 18 '21 14:11 FUTUREEEEEE

同样有疑问,我觉得你是对的

def cal_groupcenter(group, Xarray):

    center = np.zeros(Xarray.shape[1])
    for i in range(Xarray.shape[1]): #range(4)
        for n in group:
            center[i] += Xarray[n][i]  #计算当前类中第i个特征的数据之和
    center = center / Xarray.shape[0]  #计算各个特征的均值
    return center

作者您好!十分感谢你开源的机器学习代码,受益良多,想请教一下:在上面的函数中,为什么使用center = center / Xarray.shape[0] (簇的和除以总样本个数),而不是center = center / len(group) 即每一簇的中心点的均值应该是该簇的和除以该簇的数目 代码位置如下⬇ 十分感激!

https://github.com/Dod-o/Statistical-Learning-Method_Code/blob/01f6d6c9ebee258a61977137d3aadfcb5d997d04/Clustering/K-means_Clustering/K-means_Clustering.py#L101

同样有疑问并且觉得你的想法是对的

JohhnyAngel avatar Jul 15 '22 08:07 JohhnyAngel

这是来自QQ邮箱的假期自动回复邮件。你好,我最近正在休假中,无法亲自回复你的邮件。我将在假期结束后,尽快给你回复。

lingjjcn avatar Jul 15 '22 08:07 lingjjcn

def cal_groupcenter(group, Xarray):

    center = np.zeros(Xarray.shape[1])
    for i in range(Xarray.shape[1]): #range(4)
        for n in group:
            center[i] += Xarray[n][i]  #计算当前类中第i个特征的数据之和
    center = center / Xarray.shape[0]  #计算各个特征的均值
    return center

作者您好!十分感谢你开源的机器学习代码,受益良多,想请教一下:在上面的函数中,为什么使用center = center / Xarray.shape[0] (簇的和除以总样本个数),而不是center = center / len(group) 即每一簇的中心点的均值应该是该簇的和除以该簇的数目 代码位置如下⬇ 十分感激!

https://github.com/Dod-o/Statistical-Learning-Method_Code/blob/01f6d6c9ebee258a61977137d3aadfcb5d997d04/Clustering/K-means_Clustering/K-means_Clustering.py#L101

我赞成您的看法,并且我觉得应该将那个分母修改为 group.shape[0]

YiboZhao624 avatar Sep 15 '23 14:09 YiboZhao624