1. np.bincount():统计次数
numpy.bincount(x, weights=None, minlength=None)
尤其适用于计算数据集的标签列(y_train)的分布(distribution),也即获得 class distribution :
np.bincount(np.array([0, 1, 1, 3, 2, 1, 7]))
array([1, 3, 1, 1, 0, 0, 0, 1], dtype=int32)
# 分别统计0-7分别出现的次数
2.argmax
y_pred[i] = np.bincount(closest_y).argmax()
#bincount用于计数每个参数的个数,argmax用于获取数量最多的那个参数