我想对我的数据应用一种集成方法,即多数投票。我还通过“pip install mlxtend”安装了“mlxtend”。我仍然收到错误消息。以下是我得到的错误。
首先是代码:
from mlxtend.classifier import EnsembleVoteClassifier
mv_clf = MajorityVoteClassifier(classifiers=[pipe1, clf2, pipe3])
clf_labels += ['Majority Voting']
all_clf = [pipe1, clf2, pipe3, mv_clf]
for clf, label in zip(all_clf, clf_labels):
scores = cross_val_score(estimator=clf,
X=X_train,
y=y_train,
cv=10,
scoring='roc_auc')
print("Accuracy: %0.2f (+/- %0.2f) [%s]"% (scores.mean(), scores.std(), label))
注意到我之前定义了 clf1、clf2 和clf3,那部分完全没问题。
这是错误:
ImportError Traceback (most recent call last)
<ipython-input-2-9221440c28e1> in <module>()
----> 1 from mlxtend.classifier import EnsembleVoteClassifier
2 import copy
3 mv_clf = MajorityVoteClassifier(classifiers=[pipe1, clf2, pipe3])
4 clf_labels += ['Majority Voting']
5 all_clf = [pipe1, clf2, pipe3, mv_clf]
10 from .softmax_regression import SoftmaxRegression
11 from .multilayerperceptron import MultiLayerPerceptron
---> 12 from .ensemble_vote import EnsembleVoteClassifier
13 from .stacking_classification import StackingClassifier
14 from .stacking_cv_classification import StackingCVClassifier
14 from sklearn.preprocessing import LabelEncoder
15 from sklearn.base import clone
---> 16 from sklearn.exceptions import NotFittedError
17 from ..externals.name_estimators import _name_estimators
18 from ..externals import six
ImportError:没有名为异常的模块
更新:更新 scikit 学习版本后,这是我得到的错误
NameError Traceback (most recent call last)
<ipython-input-16-9643a2b164d6> in <module>()
1 from mlxtend.classifier import EnsembleVoteClassifier
2 from sklearn.ensemble import RandomForestClassifier, VotingClassifier
----> 3 mv_clf = MajorityVoteClassifier(classifiers=[pipe1, clf2, pipe3])
4
5
NameError: name 'MajorityVoteClassifier' is not defined