咱們處理feature的時候每每先要normalize encoding,使用python能夠很容易作:python
from sklearn import preprocessing from scipy.stats import rankdata x = [[1], [3], [34], [21], [10], [12]] std_x = preprocessing.StandardScaler().fit_transform(x) norm_x= preprocessing.MinMaxScaler().fit_transform(x) norm_x2= preprocessing.LabelEncoder().fit_transform(x) print('std_x=\n', std_x) print('norm_x=\n', norm_x) print('norm_2=\n', norm_x2) print('oringial order =', rankdata(x)) print('stand order =', rankdata(std_x)) print('normalize order=', rankdata(norm_x))
其中preprocessing.LabelEncoder().fit_transform(x)就是作normalize encoding,上面的程序輸入以下:spa
std_x= [[-1.1124854 ] [-0.93448773] [ 1.82447605] [ 0.66749124] [-0.31149591] [-0.13349825]] norm_x= [[0. ] [0.06060606] [1. ] [0.60606061] [0.27272727] [0.33333333]] norm_2= [0 1 5 4 2 3] oringial order = [1. 2. 6. 5. 3. 4.] stand order = [1. 2. 6. 5. 3. 4.] normalize order= [1. 2. 6. 5. 3. 4.]
能夠看到normailize以後的結果是 [0 1 5 4 2 3]。這樣作的好處是什麼呢?code
下面圖片轉自知乎(https://www.zhihu.com/questio...)orm