gpt4 book ai didi

python - 从管道获取模型属性

转载 作者:IT老高 更新时间:2023-10-28 20:31:05 25 4
gpt4 key购买 nike

我通常会得到这样的 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 = pipeline.components_ 失败:

AttributeError: 'Pipeline' object has no attribute 'components_'

(也有兴趣从管道中提取 coef_ 等属性。)

最佳答案

您是否查看过文档: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>

关于python - 从管道获取模型属性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28822756/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com