scikit-learn

fit_transform和transform这两个函数是类sklearn.preprocessing.StandardScaler()的方法,用来标准化训练和测试数据,意思就是StandardScaler类会对数据的每一个特征做单独的centering和scaling。

  • 具体操作

对于训练数据,用fit_transform。

对于测试数据,用transform。

fit用来计算mean和variance。

transform用来将所有的特征都用各自的mean和S做一些转换。

对于训练数据,需要计算train_data的mean和S,然后转换,所以需要用fit_transform。

对于测试数据,可以直接用train_data的mean和A,只需要做转换,所以只需要用transform。

  • 为什么测试数据不需要计算自己的mean和S?

因为我们想用模型去推断测试数据的表现,而不是让模型去拟合测试数据。

如果测试数据也计算自己的mean和S,那么模型就会过拟合。

  • 数据标准化是指:

rescale数据,让他们的均值为0,标准差为1

 

One such method is fit_transform() and another one is transform(). Both are the methods of class sklearn.preprocessing.StandardScaler() and ****used almost together while scaling or standardizing our training and test data.

posted @ 2023-03-11 15:29  地球美好不  阅读(114)  评论(0编辑  收藏  举报