数据分析Python:sklearn数据预处理中fit(),transform()与fit_transform()的区别
Fit():?Method calculates the parameters μ and σ and saves them as internal objects.
解釋:簡(jiǎn)單來(lái)說(shuō),就是求得訓(xùn)練集X的均值啊,方差啊,最大值啊,最小值啊這些訓(xùn)練集X固有的屬性。可以理解為一個(gè)訓(xùn)練過(guò)程
Transform():?Method using these calculated parameters apply the transformation to a particular dataset.
解釋:在Fit的基礎(chǔ)上,進(jìn)行標(biāo)準(zhǔn)化,降維,歸一化等操作(看具體用的是哪個(gè)工具,如PCA,StandardScaler等)。
Fit_transform():?joins the fit() and transform() method for transformation of dataset.
解釋:fit_transform是fit和transform的組合,既包括了訓(xùn)練又包含了轉(zhuǎn)換。
transform()和fit_transform()二者的功能都是對(duì)數(shù)據(jù)進(jìn)行某種統(tǒng)一處理(比如標(biāo)準(zhǔn)化~N(0,1),將數(shù)據(jù)縮放(映射)到某個(gè)固定區(qū)間,歸一化,正則化等)
fit_transform(trainData)對(duì)部分?jǐn)?shù)據(jù)先擬合fit,找到該part的整體指標(biāo),如均值、方差、最大值最小值等等(根據(jù)具體轉(zhuǎn)換的目的),然后對(duì)該trainData進(jìn)行轉(zhuǎn)換transform,從而實(shí)現(xiàn)數(shù)據(jù)的標(biāo)準(zhǔn)化、歸一化等等。
根據(jù)對(duì)之前部分trainData進(jìn)行fit的整體指標(biāo),對(duì)剩余的數(shù)據(jù)(testData)使用同樣的均值、方差、最大最小值等指標(biāo)進(jìn)行轉(zhuǎn)換transform(testData),從而保證train、test處理方式相同。
?
總結(jié)
以上是生活随笔為你收集整理的数据分析Python:sklearn数据预处理中fit(),transform()与fit_transform()的区别的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: 数据分析——朴素贝叶斯原理示意图
- 下一篇: 基于线性回归的波士顿房价预测