def _mean_and_std(X, axis=0, with_mean=True, with_std=True):
"""Compute mean and std deviation for centering, scaling.
Zero valued std components are reset to 1.0 to avoid NaNs when scaling.
"""
X = np.asarray(X)
Xr = np.rollaxis(X, axis)
if with_mean:
mean_ = Xr.mean(axis=0)
else:
mean_ = None
if with_std:
std_ = Xr.std(axis=0)
if isinstance(std_, np.ndarray):
std_[std_ == 0.] = 1.0
elif std_ == 0.:
std_ = 1.
else:
std_ = None
return mean_, std_
StandardScaler.py 文件源码
python
阅读 34
收藏 0
点赞 0
评论 0
评论列表
文章目录