python - Scikit-learn:preprocessing.scale() 与 preprocessing.StandardScaler()

标签 python scikit-learn scale

我理解缩放意味着以均值 (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/

相关文章:

python - 如何在没有 -A 选项的情况下运行 celery status/flower?

python - (Python 3.5.2) 如何找到我的输入是列表中的哪一项?

python - 如何获取 ZipFile 对象的文件路径?

python - 不使用 pandas 的多列标签编码

python - SVM 图像预测 Python

css - 计算缩放值以转换 iframe 以覆盖其在视口(viewport)中的内容

R 使用值列表作为色标

python - Heroku 在错误的目录中查找 Procfile

python - 在梯度增强分类器中使用sample_weight

logging - Matplotlib - 当我切换到半对数图时数据消失