手写不掉包代码实现算法的结果,如果能与sklean中的实现基本一致,那么说明才说明您对这个算法正真了解了,在这个编码的过程,将是您对python,Numpy等常用科学计算工具的实践过程,总之意义挺大,锻炼价值也很大...# 每个簇中的样本点的贡献系数之和
# gam: N by K
# return value: 1 by K
def fNk(gam):
nk = np.sum(gam,axis...,Nk,gam,x):
#print(np.shape(Nk))
for k in np.arange(0,K):
# sum : D
sumd = np.sum((gam...: N by D
shift_gam = gam[:,k].reshape(N,1)*shift
#shift2 : D by D
shift2 = shift_gam.T.dot...D
faverage(aves,Nk,gam,x)
#每个簇的方差 D by D by K
fsigma(sigmas,Nk,gam,x,aves)
# loss