基本信息
源码名称:K-means
源码大小:3.83KB
文件格式:.py
开发语言:Python
更新时间:2021-03-26
   友情提示:(无需注册或充值,赞助后即可获取资源下载链接)

     嘿,亲!知识可是无价之宝呢,但咱这精心整理的资料也耗费了不少心血呀。小小地破费一下,绝对物超所值哦!如有下载和支付问题,请联系我们QQ(微信同号):813200300

本次赞助数额为: 2 元 
   源码介绍

def gen_center(X_train, k): n_sample = X_train.shape[0] # 行数 480 n_feature = X_train.shape[1] #列数 2  # 为了在数据范围内产生随机质心,首先计算各特征的统计量 axis=1时,求各行平均值,返回n1列的矩阵  f_mean = np.mean(X_train, axis=0).reshape((1, n_feature)) # 求平均值 axis=0时,求各列平均值,返回1n列的矩阵  f_std = np.std(X_train, axis=0).reshape((1, n_feature)) # 求标准差  centers = np.random.randn(k, n_feature)*f_std f_mean #********选取的中心点*******  return centers
k=3 centers = gen_center(X_train, k)