• 11.数据归一化


    import numpy as np
    import matplotlib.pyplot as plt

    最值归一化

    x = np.random.randint(0,100,size=100)
    np.mean(x),np.std(x)
    (50.16, 28.943641788828167)
    x1 = (x - np.min(x))/(np.max(x)-np.min(x))
    np.mean(x1), np.std(x1)
    (0.5018181818181818, 0.2771724533959654)
    X = np.random.randint(0,100,(50,2))
    X[:10,:]
    array([[60., 72.],
           [50., 77.],
           [39., 84.],
           [46., 35.],
           [76.,  8.],
           [48., 78.],
           [50., 45.],
           [41., 57.],
           [61.,  4.],
           [27.,  0.]])
    X = np.array(X,dtype=float)
    X[:10,:]
    array([[60., 72.],
           [50., 77.],
           [39., 84.],
           [46., 35.],
           [76.,  8.],
           [48., 78.],
           [50., 45.],
           [41., 57.],
           [61.,  4.],
           [27.,  0.]])
    X[:,0] = (X[:,0]-np.min(X[:,0]))/(np.max(X[:,0])-np.min(X[:,0]))
    X[:,1] = (X[:,1]-np.min(X[:,1]))/(np.max(X[:,1])-np.min(X[:,1]))
    X[:10,:]
    array([[0.6185567 , 0.72727273],
           [0.51546392, 0.77777778],
           [0.40206186, 0.84848485],
           [0.4742268 , 0.35353535],
           [0.78350515, 0.08080808],
           [0.49484536, 0.78787879],
           [0.51546392, 0.45454545],
           [0.42268041, 0.57575758],
           [0.62886598, 0.04040404],
           [0.27835052, 0.        ]])
    plt.scatter(X[:,0],X[:,1])

    均值方差归一化 Standardization

    X1 = np.random.randint(0,100,(50,2))
    X1 = np.array(X1,dtype=float)
    X1[:,0] = (X1[:,0]-np.mean(X1[:,0]))/(np.std(X1[:,0]))
    X1[:,1] = (X1[:,1]-np.mean(X1[:,1]))/(np.std(X1[:,1]))
    plt.scatter(X1[:,0],X1[:,1])

    X1[:10,:]
    array([[ 0.51447692,  0.00322813],
           [-0.74357475,  0.32604148],
           [-0.41250852, -0.31958522],
           [-0.67736151, -0.0774752 ],
           [ 1.07728951,  0.20498648],
           [-0.97532111,  1.41553654],
           [-0.41250852, -0.84415691],
           [-1.14085423, -1.73189362],
           [ 0.18341069, -0.03712354],
           [-1.1077476 , -0.76345357]])
    np.min(X1[:,0])
    -1.7698800621130713
    np.max(X1[:,1])
    1.7787015556184822
    np.max(X1)
    1.7787015556184822
  • 相关阅读:
    不运用正则排除出现的特定数的数字
    重绘 贝赛尔曲线特效
    缓动类gs.TweenLite示例
    画方格(二维数组)
    递归函数
    鼠标经过延时出现Hint
    鼠标控制元件移动带缓动 鼠标点击发射子弹
    A碰到B之后持续加速度的时间问题
    播放完成之后移除动画
    hdu 1032 The 3n + 1 problem (数学)
  • 原文地址:https://www.cnblogs.com/waterr/p/14039272.html
Copyright © 2020-2023  润新知