【问题标题】:How to solve ImportError: No module named exceptions如何解决 ImportError: No module named exceptions
【发布时间】:2017-10-27 18:48:49
【问题描述】:

我想对我的数据应用一种集成方法,即多数投票。我还通过“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: No module named exceptions

更新:更新 scikit learn 版本后,这是我得到的错误

    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

【问题讨论】:

  • 您使用的是sklearnmlxtend 的哪个版本?
  • @Aurora0001sklearn:0.17.1 mlxtend:0.5.1
  • 你已经导入了EnsembleVoteClassifier,但是调用了MajorityVoteClassifier。你导入了吗?来自哪个图书馆?
  • @VivekKumar 不幸的是,似乎没有 MajorityVoteClassifier 的库了。

标签: python scikit-learn ensemble-learning


【解决方案1】:

sklearn.exceptions 模块是 introduced in version 0.18.0sklearn。您只需将安装升级到最新版本(撰写本文时为 0.18.1):

pip install --upgrade scikit-learn

如果您通过 Anaconda 安装,请使用:

conda install scikit-learn=0.18.1

这应该可以解决问题并允许您使用sklearn.exceptions 模块。

【讨论】:

  • @Aurura0001 现在它给了我另一个错误。 NameError:未定义名称“MajorityVoteClassifier”
  • @user8034918 我认为这是一个错字...您的意思是EnsembleVoteClassifier?这就是您导入的内容。
  • @user8034918 从您提供的示例中,您永远不会导入MajorityVoteClassifier,而且我在您使用的任何一个库中都找不到它。你确定你的意思是MajorityVoteClassifier吗?
  • 我想使用majorityVote 分类器,但是我在python 中找不到任何库来调用多数投票函数!!!这就是问题所在。
  • @user8034918 我的意思是MajorityVoteClassifier 不存在。您不能使用任何库中都不存在的类。你在哪里读到你特别需要MajorityVoteClassifier
猜你喜欢
  • 2016-07-04
  • 2013-08-13
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-09-10
  • 2021-05-13
  • 1970-01-01
  • 2012-08-12
相关资源
最近更新 更多