我通常会得到PCA
像这样的负载:
pca = PCA(n_components=2)
X_t = pca.fit(X).transform(X)
loadings = pca.components_
如果我跑PCA
使用 scikit-learn 管道:
from sklearn.pipeline import Pipeline
pipeline = Pipeline(steps=[
('scaling',StandardScaler()),
('pca',PCA(n_components=2))
])
X_t=pipeline.fit_transform(X)
是否可以获得负载?
只是尝试loadings = pipeline.components_
fails:
AttributeError: 'Pipeline' object has no attribute 'components_'
(也对提取属性感兴趣,例如coef_
来自管道。)
你有没有看文档:http://scikit-learn.org/dev/modules/pipeline.html http://scikit-learn.org/dev/modules/pipeline.html我觉得说的很清楚了。
更新:在 0.21 中你可以只使用方括号:
pipeline['pca']
或指数
pipeline[1]
有两种方法可以访问管道中的步骤,使用索引或使用您提供的字符串名称:
pipeline.named_steps['pca']
pipeline.steps[1][1]
这将为您提供 PCA 对象,您可以在其上获取组件。
和named_steps
您还可以使用属性访问.
它允许自动完成:
pipeline.names_steps.pca.<tab here gives autocomplete>
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)