def transform(self, X, y=None, copy=None):
"""Perform standardization by centering and scaling
Parameters
----------
X : array-like with shape [n_samples, n_features]
The data used to scale along the features axis.
"""
check_is_fitted(self, 'std_')
copy = copy if copy is not None else self.copy
X = check_array(X, copy=copy, accept_sparse="csc",
dtype=np.float32, ensure_2d=False)
if sparse.issparse(X):
if self.center_sparse:
for i in range(X.shape[1]):
X.data[X.indptr[i]:X.indptr[i + 1]] -= self.mean_[i]
elif self.with_mean:
raise ValueError(
"Cannot center sparse matrices: pass `with_mean=False` "
"instead. See docstring for motivation and alternatives.")
else:
pass
if self.std_ is not None:
inplace_column_scale(X, 1 / self.std_)
else:
if self.with_mean:
X -= self.mean_
if self.with_std:
X /= self.std_
return X
StandardScaler.py 文件源码
python
阅读 24
收藏 0
点赞 0
评论 0
评论列表
文章目录