Python 我如何才能访问;每项估计数“;在scikit中学习管道?
如何在管道中访问Python 我如何才能访问;每项估计数“;在scikit中学习管道?,python,machine-learning,scikit-learn,pipeline,Python,Machine Learning,Scikit Learn,Pipeline,如何在管道中访问“日志” 管道={ “日志”:管道( [((“scl”,StandardScaler()),(“est”,逻辑回归(随机状态=1))] ), “Rf”:管道([(“est”,RandomForestClassifier(random_state=1))), “Rf_管道”:管道( [ (“scl”,StandardScaler()), (“还原”,PCA(n_分量=10,随机状态=1)), (“est”,RandomForestClassifier(random_state=1)
“日志”
管道={
“日志”:管道(
[((“scl”,StandardScaler()),(“est”,逻辑回归(随机状态=1))]
),
“Rf”:管道([(“est”,RandomForestClassifier(random_state=1))),
“Rf_管道”:管道(
[
(“scl”,StandardScaler()),
(“还原”,PCA(n_分量=10,随机状态=1)),
(“est”,RandomForestClassifier(random_state=1)),
]
),
}
管道。项目(日志)
目前我得到:
NameError: name 'Log' is not defined
管道对象可以被视为字典。在本例中,您已经将多个管道存储到一个字典中。要访问不同的键(管道),只需使用
dict['key']
或dict.get['key']
dict['key']
命名的步骤获取dict
,然后以相同的方式引用每个步骤
from sklearn.pipeline import Pipeline
from sklearn.preprocessing import StandardScaler
from sklearn.linear_model import LogisticRegression
from sklearn.decomposition import PCA
from sklearn.ensemble import RandomForestClassifier
pipelines = {
"Log": Pipeline(
[("scl", StandardScaler()), ("est", LogisticRegression(random_state=1))]
),
"Rf": Pipeline([("est", RandomForestClassifier(random_state=1))]),
"Rf_Pipeline": Pipeline(
[
("scl", StandardScaler()),
("reduct", PCA(n_components=10, random_state=1)),
("est", RandomForestClassifier(random_state=1)),
]
),
}
first_subpipeline = pipelines['Log']
second_step_first_subpipeline = pipelines['Log'].named_steps['est']
print(first_subpipeline)
print(second_step_first_subpipeline)
从字典中获取项目时,可以使用
pipelines[“Log”]
或pipelines.get(“Log”)
。您的管道名为pipelines
,而不是pipelines
,首字母大写L(打字)。感谢您的修改。非常有用。我尝试了此代码,现在一切都清楚了。非常感谢你!!
Pipeline(steps=[('scl', StandardScaler()),
('est', LogisticRegression(random_state=1))])
LogisticRegression(random_state=1)