一些自己的机器学习函数(方便自己复制粘贴)

1、降采样

def down_sample(train_x,train_y):
    train_0 = train_x[np.where(train_y == 0)]
    train_0_y = train_y[np.where(train_y == 0)]
    train_1 = train_x[np.where(train_y == 1)]
    train_1_y = train_y[np.where(train_y == 1)]
    if train_0.shape[0]>train_1.shape[0]:
        return np.concatenate((train_0[:train_1.shape[0]],train_1),axis=0),np.concatenate((train_0_y[:train_1.shape[0]],train_1_y),axis=0)
    else:
        return np.concatenate((train_1[:train_0.shape[0]],train_0),axis=0),np.concatenate((train_1_y[:train_0.shape[0]],train_0_y),axis=0)

上一篇:设计模式七大原则——开闭原则


下一篇:微信小程序生成带参数的二维码(小程序码)独家asp.net的服务端c#完整代码