Sklearn的MinMaxScaler,最简单的归一化

import numpy as np
from sklearn.preprocessing import MinMaxScaler

a=np.array([1,2,3,4,5], dtype='float64')
print('a-1D:', a, a.shape)
a=a.reshape(-1,1)
print('a-2D:', a, a.shape)

scaler_2 = MinMaxScaler(feature_range=(0, 1))  #自动将dtype转换成float64
scaled = scaler_2.fit_transform(a)
print('a-transformed:', scaled)

inv_a = scaler_2.inverse_transform(scaled)
print('a-inversed:',inv_a)
a-1D:
 [1. 2. 3. 4. 5.] (5,)
a-2D:
 [[1.]
 [2.]
 [3.]
 [4.]
 [5.]] (5, 1)
a-transformed:
 [[0.  ]
 [0.25]
 [0.5 ]
 [0.75]
 [1.  ]]
a-inversed:
 [[1.]
 [2.]
 [3.]
 [4.]
 [5.]]

你可能感兴趣的:(sklearn,minmax,scaler)