lma*_*999 33 python scikit-learn neuraxle
我通常得到这样的PCA负载:
pca = PCA(n_components=2)
X_t = pca.fit(X).transform(X)
loadings = pca.components_
Run Code Online (Sandbox Code Playgroud)
如果我PCA使用scikit-learnpipline 运行...
from sklearn.pipeline import Pipeline
pipeline = Pipeline(steps=[
('scaling',StandardScaler()),
('pca',PCA(n_components=2))
])
X_t=pipeline.fit_transform(X)
Run Code Online (Sandbox Code Playgroud)
......有可能获得负荷吗?
只是尝试loadings = pipeline.components_失败:
AttributeError: 'Pipeline' object has no attribute 'components_'
Run Code Online (Sandbox Code Playgroud)
谢谢!
(也有兴趣coef_从学习管道中提取属性.)
And*_*ler 62
您是否看过文档:http://scikit-learn.org/dev/modules/pipeline.html 我觉得很清楚.
有两种方法可以使用索引或使用您给出的字符串名称来获取管道中的步骤:
pipeline['pca']
Run Code Online (Sandbox Code Playgroud)
这将为您提供PCA对象,您可以在其上获取组件.
使用Neuraxle可以更轻松地处理管道。例如,您可以执行以下操作:
from neuraxle.pipeline import Pipeline
# Create and fit the pipeline:
pipeline = Pipeline([
StandardScaler(),
PCA(n_components=2)
])
pipeline, X_t = pipeline.fit_transform(X)
# Get the components:
pca = pipeline[-1]
components = pca.components_
Run Code Online (Sandbox Code Playgroud)
您可以按照以下三种方式访问PCA:
pipeline['PCA']pipeline[-1]pipeline[1]Neuraxle是基于scikit-learn构建的流水线库,可将流水线带入新的水平。它允许轻松管理超参数分布,嵌套管道,保存和重新加载,REST API服务等的空间。整个过程还使用了深度学习算法并允许并行计算。
您可以在管道中包含管道,如下所示。
# Create and fit the pipeline:
pipeline = Pipeline([
StandardScaler(),
Identity(),
Pipeline([
Identity(), # Note: an Identity step is a step that does nothing.
Identity(), # We use it here for demonstration purposes.
Identity(),
Pipeline([
Identity(),
PCA(n_components=2)
])
])
])
pipeline, X_t = pipeline.fit_transform(X)
Run Code Online (Sandbox Code Playgroud)
然后,您需要执行以下操作:
# Get the components:
pca = pipeline["Pipeline"]["Pipeline"][-1]
components = pca.components_
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
21491 次 |
| 最近记录: |