是否可以在sklearn.pipeline.Pipeline
对象中删除或插入步骤?
我正在尝试在Pipeline对象中进行一步或不一步的网格搜索。想知道是否可以在管道中插入或删除步骤。我在Pipeline
源代码中看到,有一个包含self.steps
所有步骤的对象。我们可以按步骤进行操作named_steps()
。在修改它之前,我要确保不会引起意外的影响。
这是示例代码:
from sklearn.pipeline import Pipeline
from sklearn.svm import SVC
from sklearn.decomposition import PCA
estimators = [('reduce_dim', PCA()), ('svm', SVC())]
clf = Pipeline(estimators)
clf
我们是否可以执行类似的操作steps = clf.named_steps()
,然后在此列表中插入或删除?这会对clf对象产生不良影响吗?
我看到每个人都只提到删除步骤。如果您还想在管道中插入一个步骤:
pipe.steps.append(['step name',transformer()])
pipe.steps
的工作方式与列表相同,因此您还可以将项目插入特定位置:
pipe.steps.insert(1,['estimator',transformer()]) #insert as second step
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句