preprocessing.StandardScaler()

sklearn.preprcoessing包下有很多数据预处理的方法,preprocessing模块中StandardScaler()类的fit()函数也可以用于数组的标准化。

官方说明文档icon-default.png?t=M5H6https://scikit-learn.org/stable/modules/generated/sklearn.preprocessing.StandardScaler.html

参数:

class sklearn.preprocessing.StandardScaler(*copy=Truewith_mean=Truewith_std=True)

copy,布尔类型,默认为True,当设置其为 False 时,执行就地行的标准化,避免复制(如果输入已经是 numpy 数组或 scipy.sparse CSC 矩阵并且axis为 1);如果数据不是numpy数组或scipy.sparse CSR矩阵,仍然可以返回副本。

with_mean,布尔类型,默认为True,表示处理后的数据均值为0。

with_std,布尔类型,默认为True,表示处理后的数据方差为1。

代码示例:

首先,调用preprocessing模块中StandardScaler()类的fit()函数,通过数组x_train(待处理的数组)构建标准化模型scaler。

然后,调用模型scaler的transform函数,就可以对x_train数组进行标准化啦。

scaler=preprocessing.StandardScaler().fit(x_train) 
scaler.transform(x_train)

你可能感兴趣的:(sklearn,sklearn,python,机器学习,人工智能)