2015-03-03 62 views
14

我通常得到PCA載荷這樣的:獲取模型從屬性scikit學習管道

pca = PCA(n_components=2) 
X_t = pca.fit(X).transform(X) 
loadings = pca.components_ 

如果我使用scikit-learn pipline運行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_屬性)

回答

26

難道你看的文檔:http://scikit-learn.org/dev/modules/pipeline.html 我覺得這是很清楚的。

有兩種方式可以進入管道中的步驟,或者使用索引或使用您給字符串名稱:

pipeline.named_steps['pca'] 
pipeline.steps[1][1] 

這會給你的PCA對象,您可以在其中得到的組件。

+0

對,謝謝。沒有([使用'named_steps')在[doc here](http://scikit-learn.org/dev/modules/generated/sklearn.pipeline.Pipeline.html#sklearn.pipeline.Pipeline)。感謝。 – lmart999 2015-03-03 23:52:35

+0

真棒:)謝謝 – AbtPst 2015-12-15 19:36:20