我想对我的数据应用其中一种集合方法,多数投票。我还安装了" mlxtend"通过" pip install 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
答案 0 :(得分:0)
sklearn.exceptions
模块是sklearn
的{{3}}。您只需将安装升级到最新版本(撰写本文时为0.18.1):
pip install --upgrade scikit-learn
如果您通过Anaconda安装,请使用:
conda install scikit-learn=0.18.1
这应解决问题并允许您使用sklearn.exceptions
模块。