分类

def classify(in_x, groups, labels, k):
    """分类"""
    # 计算欧式距离
    gl = array_len(groups)
    tmp = tile(in_x, (gl, 1)) - groups
    tmp = exponential_operation(tmp, 2)
    tmp = array_sum(tmp)
    tmp = exponential_operation(tmp, 0.5)

    # 得到排序后的数组的索引
    arg = argsort(tmp)

    # 计算最相似数据的前k个数据的分类次数
    cc = odict()
    for i in range(k):
        # 获得类别次数
        la = labels[arg[i]]
        cc[la] = cc.get(la, 0) + 1
    return max(cc)