-
Notifications
You must be signed in to change notification settings - Fork 2.9k
Open
Description
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) 即每一簇的中心点的均值应该是该簇的和除以该簇的数目
代码位置如下⬇ 十分感激!
Statistical-Learning-Method_Code/Clustering/K-means_Clustering/K-means_Clustering.py
Line 101 in 01f6d6c
center = center / Xarray.shape[0] #计算各个特征的均值 |
Metadata
Metadata
Assignees
Labels
No labels