我理解缩放意味着以均值 (mean=0) 为中心并使单位方差 (variance=1)。
但是,scikit-learn 中的 preprocessing.scale(x)
和 preprocessing.StandardScalar()
有什么区别?
最佳答案
它们做的完全一样,但是:
preprocessing.scale(x)
只是一个函数,它转换一些数据preprocessing.StandardScaler()
是一个支持 Transformer API 的类
我会一直使用后者,即使我不需要 inverse_transform
和 co。由 StandardScaler()
支持。
摘自 docs :
The function scale provides a quick and easy way to perform this operation on a single array-like dataset
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
关于python - Scikit-learn:preprocessing.scale() 与 preprocessing.StandardScaler(),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46257627/