学习目标:
机器学习----数据预处理
学习内容:
1、 均值移除、范围缩放 2、归一化 3、二值化 4、 独热编码、标签编码
学习记录:
import numpy as np
import sklearn.preprocessing as sp
raw_samples = np.array([
[17, 90, 4000],
[20, 80, 5000],
[23, 75, 5500]
])
result = sp.scale(raw_samples)
print(result)
import numpy as np
import sklearn.preprocessing as sp
raw_samples = np.array([
[17, 90, 4000],
[20, 80, 5000],
[23, 75, 5500]
])
mms = sp.MinMaxScaler(feature_range=(0, 1))
result = mms.fit_transform(raw_samples)
print(result)
import numpy as np
import sklearn.preprocessing as sp
ary = np.array([
[10, 21, 5],
[2, 4, 1],
[11, 18, 18]
])
result = sp.normalize(ary, norm='l1')
print(result)
import numpy as np
import sklearn.preprocessing as sp
ary = np.array([
[10, 21, 5],
[2, 4, 1],
[11, 18, 18]
])
bin = sp.Binarizer(threshold=10)
result = bin.transform(ary)
print(result)
import numpy as np
import sklearn.preprocessing as sp
samples=np.array([
[1,3,2],
[7,5,4],
[1,8,6],
[7,3,9]
])
ohe=sp.OneHotEncoder(sparse=False,dtype='int32')
result=ohe.fit_transform(samples)
print(result)
import numpy as np
import sklearn.preprocessing as sp
raw_sample=np.array(['zhao','qian','sun','li','zhou',
'li','qian','zhao','wu','wu'])
lbe=sp.LabelEncoder()
result=lbe.fit_transform(raw_sample)
sample=lbe.inverse_transform(result)