sklearn——数据标准化

本文介绍了如何使用sklearn库的preprocessing模块进行数据标准化,包括函数sklearn.preprocessing.scale的参数解析。通过示例展示了如何对数据进行中心化和标准化处理,并强调了使用StandardScaler类在训练和测试集之间的优势。
摘要由CSDN通过智能技术生成

数据集标准化

函数:
sklearn.preprocessing.scale(X, axis=0, with_mean=True, with_std=True, copy=True)

参数解释:
X : {array-like, sparse matrix}
要标准化的数据,numpy的array类数据。

axis : int (0 by default)
0表示特征的标准化,1表示样本的标准化。默认为0。

with_mean : boolean, True by default
是否中心化。

with_std : boolean, True by default
是否标准化。

copy : boolean, optional, default True
是否复制。

代码实例:

from sklearn.preprocessing import scale
import numpy as np

X = np.array([[ 1.,-1.,2.],[ 2.,0.,0.],[ 0.,1.,-1.]])
x_scale=scale(X=X,with_mean=True,with_std=True,copy=True)
print('原始数据:\n',X)
print('标准化数据:\n',x_scale)

运行结果为:

原始数据:
 [[ 1. -1.  2.]
 [ 2.  0.  0.]
 [ 0.  1. -1.]]

标准化数据:
 [[ 0.         -1.22474487  1.33630621]
 [
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值