[译]sklearn.preprocessing.StandardScaler
发布日期:2021-05-07 14:32:31 浏览次数:29 分类:原创文章

本文共 1138 字,大约阅读时间需要 3 分钟。




class sklearn.preprocessing.StandardScaler(copy=True, with_mean=True, with_std=True)


通过去除均值和缩放为单位变量实现特征标准化。


计算方式为
z = x − μ s z=\frac{x-\mu}{s} z=sxμ
μ \mu μ是训练样本的均值或者为0(当with_mean=False), s s s是标准差或者1(如果with_std=False


针对么个特征通过计算训练样本的相关统计量实现中心化和缩放独立进行,均值和标准差会被存储一遍后续transform方法使用。


数据集的标准化是很多机器学习算法常见的要求:这些算法可能会表现低劣如果独立特征不是或多或少呈现标准正态分布。


例如,一个学习算法(如SVM算法的RBF核,线性模型的L1、L2正则因子)目标函数中常用的元素假定所有特征均值为0,且同方差。


如果一个特征的方差比其他的量级要大,它可能会主宰目标函数,导致模型不能正确的从其它特征处学到本质的规律。


这个定标器也可用于sparse CSR or CSC 矩阵通过with_mean=False避免破坏数据的稀疏结构



  • Parameters




























Parameters 数据结构 意义
copy boolean, optional, default True False:不保存副本,立即缩放
with_mean boolean, True by default True:指定数据中心。
with_std boolean, True by default True:以单位标准差缩放


  • Attributes

































Attributes 数据结构 意义
scale_ ndarray or None, shape (n_features,)
mean_ ndarray or None, shape (n_features,)
var_ ndarray or None, shape (n_features,)
n_samples_seen_ int or array, shape (n_features,)


  • Methods








































Methods 意义
(self, X[, y]) 计算缩放用的均值和方差
(self, X[, y]) 拟合,然后转换
(self[, deep]) 获取参数
(self, X[, copy]) 将数据返回原始形式
(self, X[, y]) Online computation of mean and std on X for later scaling.
(self, **params) 设置参数
(self, X[, copy]) 执行标准化
上一篇:[译]tocsc()
下一篇:[译]sklearn.decomposition.TruncatedSVD

发表评论

最新留言

路过,博主的博客真漂亮。。
[***.116.15.85]2025年03月23日 19时12分12秒