[英]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
相当于在同一输入矩阵上连续运行fit
和transform
。 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.因此,要拟合一个矩阵,并将从该矩阵学到的居中参数应用到另一个矩阵(例如,将在训练集上学到的模型应用于测试/验证集时),您需要分别使用fit
和transform
.
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.