Scikit-learn:preprocessing.scale() 与 preprocessing.StandardScalar() [英] Scikit-learn: preprocessing.scale() vs preprocessing.StandardScalar()
问题描述
我理解缩放意味着将均值(均值 = 0)居中并制作单位方差(方差 = 1).
I understand that scaling means centering the mean(mean=0) and making unit variance(variance=1).
但是,scikit-learn 中的 preprocessing.scale(x)
和 preprocessing.StandardScalar()
有什么区别?
But, What is the difference between preprocessing.scale(x)
and preprocessing.StandardScalar()
in scikit-learn?
推荐答案
那些做的完全一样,但是:
Those are doing exactly the same, but:
preprocessing.scale(x)
只是一个函数,它转换一些数据preprocessing.StandardScaler()
是一个支持 Transformer API 的类
preprocessing.scale(x)
is just a function, which transforms some datapreprocessing.StandardScaler()
is a class supporting the Transformer API
我总是使用后者,即使我不需要 inverse_transform
和 co.StandardScaler()
支持.
I would always use the latter, even if i would not need inverse_transform
and co. supported by StandardScaler()
.
摘自 文档:
函数 scale 提供了一种快速简便的方法来对单个类似数组的数据集执行此操作
The function scale provides a quick and easy way to perform this operation on a single array-like dataset
预处理模块进一步提供了一个实用程序类 StandardScaler,它实现了 Transformer API 来计算训练集的均值和标准差,以便以后能够在测试集上重新应用相同的变换.因此,此类适用于 sklearn.pipeline.Pipeline
The preprocessing module further provides a utility class StandardScaler that implements the Transformer API to compute the mean and standard deviation on a training set so as to be able to later reapply the same transformation on the testing set. This class is hence suitable for use in the early steps of a sklearn.pipeline.Pipeline
这篇关于Scikit-learn:preprocessing.scale() 与 preprocessing.StandardScalar()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!