我想使用VotingClassifier
里面的 a sklearn Pipeline
,我在其中定义了一组分类器 ..
我从这个问题中得到了一些直觉:Using VotingClassifier
in Sklearn Pipeline to build the code below,但是在这个问题中,每个分类器都定义在一个独立的管道中。我不想以这种方式使用它,我有一个之前准备了一组特征,在具有不同分类器的多个管道中重复生成这些特征不是一个好主意(耗时的过程)!
我怎么能做到这一点?!
model = Pipeline([
('feat', FeatureUnion([
('tfidf', TfidfVectorizer(analyzer='char', ngram_range=(3, 5), min_df=0.01, lowercase=True, tokenizer=tokenizeTfidf)),
])),
('pip1', Pipeline([('clf1', GradientBoostingClassifier(n_estimators=1000, random_state=7))])),
('pip2', Pipeline([('clf2', SVC())])),
('pip3', Pipeline([('clf3', RandomForestClassifier())])),
('clf', VotingClassifier(estimators=["pip1", "pip2", "pip3"]))
])
clf = model.fit(X_train, y_train)
但我收到了这个错误:
('clf', VotingClassifier(estimators=["pip1", "pip2", "pip3"])),
File "C:\Python35\lib\site-packages\imblearn\pipeline.py", line 115, in __init__
self._validate_steps()
File "C:\Python35\lib\site-packages\imblearn\pipeline.py", line 139, in _validate_steps
"(but not both) '%s' (type %s) doesn't)" % (t, type(t)))
TypeError: All intermediate steps of the chain should be estimators that implement fit and transform or sample (but not both) 'Pipeline(memory=None,
steps=[('clf1', GradientBoostingClassifier(criterion='friedman_mse', init=None,
learning_rate=0.1, loss='deviance', max_depth=3,
max_features=None, max_leaf_nodes=None,
min_impurity_decrease=0.0, min_impurity_split=None,
min_samples_leaf=1, min_samples_split=2,
min_weight_fraction_leaf=0.0, n_estimators=1000,
presort='auto', random_state=7, subsample=1.0, verbose=0,
warm_start=False))])' (type <class 'imblearn.pipeline.Pipeline'>) doesn't)