我通常会得到类似这样的PCA
载荷:
pca = PCA(n_components=2)
X_t = pca.fit(X).transform(X)
loadings = pca.components_
如果我使用scikit-learn管道运行PCA
:
from sklearn.pipeline import Pipeline
pipeline = Pipeline(steps=[
('scaling',StandardScaler()),
('pca',PCA(n_components=2))
])
X_t=pipeline.fit_transform(X)
能否获取载荷(loadings)?
尝试使用loadings = pipeline.components_
这样简单的方法会失败:
AttributeError: 'Pipeline' object has no attribute 'components_'
(还对从管道中提取类似于 coef_
的属性感兴趣。)
named_steps
是吗?感激不尽。 - lmart999regr = TransformedTargetRegressor
,那么语法就不同了,你必须在访问命名步骤之前使用regressor_
访问回归器,例如regr.regressor_.named_steps['pca'].components_
。 - Ari Cooper-Davis