sklearn 数据预处理

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...]])
原文地址:https://www.cnblogs.com/eclipSycn/p/7193676.html