scikit-learn fit() transfrom() fit_transform()

转载 2018年04月17日 11:15:45

https://stackoverflow.com/questions/23838056/what-is-the-difference-between-transform-and-fit-transform-in-sklearn

In scikit-learn estimator api,

fit() : used for generating learning model parameters from training data

transform() : parameters generated from fit() method,applied upon model to generate transformed data set.

fit_transform() :combination of fit() and transform() api on same data set

enter image description here

Checkout Chapter-4 from this book & answer from stackexchange for more clarity


Further more explanation as follows (an example to explain the meaning of fit() and fit_transform() ):

To center the data (make it have zero mean and unit standard error), you subtract the mean and then divide the result by the standard deviation.

You do that on the training set of data. But then you have to apply the same transformation to your testing set (e.g. in cross-validation), or to newly obtained examples before forecast. But you have to use the same two parameters μ and σ  (values) that you used for centering the training set.

Hence, every sklearn's transform's fit() just calculates the parameters (e.g. μ and σ  in case of StandardScaler) and saves them as an internal objects state. Afterwards, you can call its transform() method to apply the transformation to a particular set of examples.

fit_transform() joins these two steps and is used for the initial fitting of parameters on the training set x, but it also returns a transformed x. Internally, it just calls first fit() and then transform() on the same data.

scikit-learn数据预处理fit_transform()与transform()的区别(转)

二者的功能都是对数据进行某种统一处理(比如标准化~N(0,1),将数据缩放(映射)到某个固定区间,归一化,正则化等)fit_transform(partData)对部分数据先拟合fit,找到该part...
  • SDUTyangkun
  • SDUTyangkun
  • 2017-08-22 21:30:08
  • 1014

Scikit-Learn使用总结

scikit-learn提供了一系列转换库,他们可以清洗,降维,提取特征等。在数据转换中有三个很重要的方法,fit,fit_transform,transformss=StandardScaler()...
  • silence2015
  • silence2015
  • 2017-02-27 21:26:06
  • 2859

Python: sklearn库中数据预处理函数fit_transform()和transform()的区别

敲《Python机器学习及实践》上的code的时候,对于数据预处理中涉及到的fit_transform()函数和transform()函数之间的区别很模糊,查阅了很多资料,这里整理一下: 涉...
  • quiet_girl
  • quiet_girl
  • 2017-05-19 09:48:40
  • 13233

scikit-learn数据预处理fit_transform()与transform()的区别

scikit-learn中fit_transform()与transform()到底有什么区别?
  • anecdotegyb
  • anecdotegyb
  • 2017-07-09 04:21:12
  • 4351

sklearn 中 fit fit_transform

fit(y) Fit label encoder fit_transform(y) Fit label encoder and return encoded labels fit 返回一个...
  • qq_29031319
  • qq_29031319
  • 2017-04-07 16:48:14
  • 1582

fit_transform和transform的区别

针对sklearn中的transform和fit_transform进行比较
  • Kaido0
  • Kaido0
  • 2016-10-30 20:37:59
  • 11496

通俗地讲清楚fit_transform()和transform()的区别

网上抄来抄去都是一个意思, fit_transform是fit和transform的组合。  我们知道fit(x,y)在新手入门的例子中比较多,但是这里的fit_transform(x)的括号中只...
  • appleyuchi
  • appleyuchi
  • 2017-06-20 17:21:58
  • 8611

NLP:sklearn中fit、fit_transform、transform的区别

参考:http://blog.csdn.net/qq_35082030/article/details/70338654fit原义指的是安装、使适合的意思,其实有点train的含义但是和train不同...
  • LUFANGBO
  • LUFANGBO
  • 2018-02-11 09:33:27
  • 245

数据预处理sklearn.preprocessing中,fit_transform()和transform()的区别?

 scikit-learn中fit_transform()与transform()到底有什么区别,能不能混用? 二者的功能都是对数据进行某种统一处理(比如标准化~N(0,1),将数据缩放(映射...
  • Qbluesky
  • Qbluesky
  • 2017-09-16 11:19:26
  • 508

sklearn中的fit fit_transform和transfrom区别

参考文章一:https://www.jianshu.com/p/ddfe1909b8db参考文章二:http://blog.csdn.net/appleyuchi/article/details/73...
  • m0_37870649
  • m0_37870649
  • 2018-03-13 21:35:53
  • 18
收藏助手
不良信息举报
您举报文章:scikit-learn fit() transfrom() fit_transform()
举报原因:
原因补充:

(最多只允许输入30个字)