码迷,mamicode.com
首页 > 其他好文 > 详细

sklearn 数据预处理

时间:2017-07-17 13:19:12      阅读:275      评论:0      收藏:0      [点我收藏+]

标签:style   com   方差   1.2   standards   www   code   array   http   

http://www.cnblogs.com/chaosimple/p/4153167.html

其中介绍了sklearn.preprocessing.StandardScaler类,使用该类的好处在于可以保存训练集中的参数(均值、方差)直接使用其对象转换测试集数据。

>>> scaler = preprocessing.StandardScaler().fit(X)
>>> scaler
StandardScaler(copy=True, with_mean=True, with_std=True)
 
>>> scaler.mean_                                      
array([ 1. ...,  0. ...,  0.33...])
 
>>> scaler.std_                                       
array([ 0.81...,  0.81...,  1.24...])
 
>>> scaler.transform(X)                               
array([[ 0.  ..., -1.22...,  1.33...],
       [ 1.22...,  0.  ..., -0.26...],
       [-1.22...,  1.22..., -1.06...]])
 
 
>>>#可以直接使用训练集对测试集数据进行转换
>>> scaler.transform([[-1.,  1., 0.]])                
array([[-2.44...,  1.22..., -0.26...]])

 

sklearn 数据预处理

标签:style   com   方差   1.2   standards   www   code   array   http   

原文地址:http://www.cnblogs.com/eclipSycn/p/7193676.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!