归一化
标准化
from sklearn.preprocessing import MinMaxScaler ,StandardScaler,Imputer
import numpy as np
def mm():
"""
归一化处理
:return:
"""
#mm = MinMaxScaler() 不指定范围,默认[0,1]
mm = MinMaxScaler(feature_range=(2,3)) # 指定范围
data = mm.fit_transform([[90,2,10,40],[60,4,15,45],[75,3,13,46]])
print(data)
def stand():
"""
标准化缩放
:return:
"""
std = StandardScaler()
data = std.fit_transform([[1,-1,3],[2,4,2],[4,6,-1]])
print(data)
def im():
"""
缺失值
:return:
"""
im = Imputer(missing_values="NaN",strategy="mean",axis=0) # axis=0 是按列
data = im.fit_transform([[1,2],[np.nan,3],[7,6]])
print(data)
if __name__ == "__main__":
mm()
stand()
im()
结果: