sklearn PCA fit_transform() 是否以输入变量为中心?
Does sklearn PCA fit_transform() center input variables?
标题中的问题。在调用 pca.fit(X)
之后,假设我调用了 pca.fit_transform(new_X)
。 new_X
是PCA 自动居中的吗?文档在这一点上不清楚。
来自文档:
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.
https://scikit-learn.org/stable/modules/generated/sklearn.decomposition.PCA.html
fit_transform
相当于在同一输入矩阵上连续 运行 fit
和 transform
。 fit
函数计算数据居中的均值,transform
函数使用 fit
期间计算的均值应用均值居中。
因此,要拟合一个矩阵,并将从该矩阵学习到的居中参数应用到另一个矩阵(例如,将在训练集上学习的模型应用到 test/validation 集时),您会需要分别使用fit
和transform
。
标题中的问题。在调用 pca.fit(X)
之后,假设我调用了 pca.fit_transform(new_X)
。 new_X
是PCA 自动居中的吗?文档在这一点上不清楚。
来自文档:
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.
https://scikit-learn.org/stable/modules/generated/sklearn.decomposition.PCA.html
fit_transform
相当于在同一输入矩阵上连续 运行 fit
和 transform
。 fit
函数计算数据居中的均值,transform
函数使用 fit
期间计算的均值应用均值居中。
因此,要拟合一个矩阵,并将从该矩阵学习到的居中参数应用到另一个矩阵(例如,将在训练集上学习的模型应用到 test/validation 集时),您会需要分别使用fit
和transform
。