一、标准化(Z-Score)
使用sklearn.preprocessing.scale()函数,可以直接将给定数据进行标准化。
from sklearn import preprocessing
X_scaled = preprocessing.scale(X)
使用sklearn.preprocessing.StandardScaler类,使用该类的好处在于可以保存训练集中的参数(均值、方差)直接使用其对象转换测试集数据。
from sklearn.preprocessing import StandardScaler
scaler = StandardScaler()
data_train[predictors]<