数据集标准化
函数:
sklearn.preprocessing.scale(X, axis=0, with_mean=True, with_std=True, copy=True)
参数解释:
X : {array-like, sparse matrix}
要标准化的数据,numpy的array类数据。
axis : int (0 by default)
0表示特征的标准化,1表示样本的标准化。默认为0。
with_mean : boolean, True by default
是否中心化。
with_std : boolean, True by default
是否标准化。
copy : boolean, optional, default True
是否复制。
代码实例:
from sklearn.preprocessing import scale
import numpy as np
X = np.array([[ 1.,-1.,2.],[ 2.,0.,0.],[ 0.,1.,-1.]])
x_scale=scale(X=X,with_mean=True,with_std=True,copy=True)
print('原始数据:\n',X)
print('标准化数据:\n',x_scale)
运行结果为:
原始数据:
[[ 1. -1. 2.]
[ 2. 0. 0.]
[ 0. 1. -1.]]
标准化数据:
[[ 0. -1.22474487 1.33630621]
[