简体   繁体   English

sklearn PCA fit_transform() 是否以输入变量为中心?

[英]Does sklearn PCA fit_transform() center input variables?

Question in the title.标题中的问题。 After calling pca.fit(X) , suppose I called pca.fit_transform(new_X) .调用pca.fit(X) ,假设我调用了pca.fit_transform(new_X) Is new_X automatically centered by PCA? new_X是否由 PCA 自动居中? The documentation is unclear on this point.文档在这一点上不清楚。

From the docs:从文档:

Linear dimensionality reduction using Singular Value Decomposition of the data to project it to a lower dimensional space.使用数据的奇异值分解将其投影到较低维空间的线性降维。 The input data is centered but not scaled for each feature before applying the SVD.在应用 SVD 之前,输入数据已居中但未针对每个特征进行缩放。

https://scikit-learn.org/stable/modules/generated/sklearn.decomposition.PCA.html https://scikit-learn.org/stable/modules/generated/sklearn.decomposition.PCA.html

fit_transform is just the equivalent of running fit and transform consecutively on the same input matrix. fit_transform相当于在同一输入矩阵上连续运行fittransform The fit function calculates the means for centering the data, and the transform function applies the mean centering using the means calculated during fit . fit函数计算数据居中的均值, transform函数使用fit期间计算的均值应用均值居中。

Therefore to fit on one matrix, and apply the centering parameters learnt from that matrix to another (as, for example, when applying a model learnt on a training set to a test/validation set), you would need to use fit and transform separately.因此,要拟合一个矩阵,并将从该矩阵学到的居中参数应用到另一个矩阵(例如,将在训练集上学到的模型应用于测试/验证集时),您需要分别使用fittransform .

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 sklearn.decomposition 中的 PCA 中的 fit、transform 和 fit_transform 有什么作用? - What does fit, transform, and fit_transform do in PCA available in sklearn.decomposition? sklearn SVD fit_transform函数的输入数据类型 - Input data type for sklearn SVD fit_transform function Python sklearn:fit_transform()不适用于GridSearchCV - Python sklearn : fit_transform() does not work for GridSearchCV fit_transform PCA结果不一致 - fit_transform PCA inconsistent results 矢量化fit_transform如何在sklearn中工作? - How vectorizer fit_transform work in sklearn? CountVectorizer().fit_transform() 是否保留输入顺序? - Does CountVectorizer().fit_transform() preserve order of input? sklearn.impute SimpleImputer:为什么transform()首先需要fit_transform()? - sklearn.impute SimpleImputer: why does transform() need fit_transform() first? sklearn countvectorizer 中的 fit_transform 和 transform 有什么区别? - What is the difference between fit_transform and transform in sklearn countvectorizer? sklearn中的'transform'和'fit_transform'有什么区别 - what is the difference between 'transform' and 'fit_transform' in sklearn 为什么fit_transform在此sklearn Pipeline示例中不起作用? - Why doesn't fit_transform work in this sklearn Pipeline example?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM