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