简体   繁体   English

sklearn.ensemble ImportError 中的 VotingClassifier

[英]VotingClassifier in sklearn.ensemble ImportError

I am trying to implement multiple learning classifiers in python.我正在尝试在 python 中实现多个学习分类器。 I have 5 random forest classifiers in the code but now I am not able to import the VotingClassifier function from sklearn.ensemble .我在代码中有 5 个随机森林分类器,但现在我无法从sklearn.ensemble导入VotingClassifier函数。

When I write this:当我写这个:

from sklearn.ensemble import VotingClassifier

the error says:错误说:

ImportError: cannot import name VotingClassifier 

How can I fix this?我怎样才能解决这个问题?

I am the person who implemented the VotingClassifier in scikit-learn.我是在 scikit-learn 中实现VotingClassifier的人。 Sorry for the confusion, I just stumbled upon the "examples" section in the scikit-learn 16.1 documentation.抱歉造成混淆,我只是偶然发现了 scikit-learn 16.1 文档中的“示例”部分。 This is a little bit misleading, the VotingClassifier is already implemented but will be in the next version of scikit-learn 0.17.这有点误导, VotingClassifier器已经实现,但将在 scikit-learn 0.17 的下一个版本中实现。

If you want to use it "already" you have 2 options:如果你想“已经”使用它,你有两个选择:

1) you could install the current scikit-learn dev version available via GitHub: https://github.com/scikit-learn/scikit-learn (instructions are in the Readme) 1) 您可以通过 GitHub 安装当前可用的 scikit-learn 开发版本: https : //github.com/scikit-learn/scikit-learn (说明在自述文件中)

2) alternatively, you could use it from mlxtend as EnsembleClassifier ( http://rasbt.github.io/mlxtend/docs/classifier/scikit-learn_ensemble_classifier/ ) until the new scikit-version comes out. 2) 或者,您可以将mlxtend它用作EnsembleClassifier ( http://rasbt.github.io/mlxtend/docs/classifier/scikit-learn_ensemble_classifier/ ),直到新的 scikit-version 出现。 The mlxtend package is a little "playground" of mine where I upload some examples and functions that I find useful at times. mlxtend包是我的一个小“游乐场”,我上传了一些我觉得有时有用的示例和函数。

Hope that helps!希望有帮助!

Q: How can I fix this?问:我该如何解决这个问题?

Your issue is clear & solve-able.您的问题很明确且可以解决。 The devil hides in the detail.魔鬼藏在细节中。 VotingClassifier was announced in a scikit-learn changelog to be the add-on right for the still-wet-ink release of 0.17.0 . VotingClassifier在 scikit-learn 更新日志中被宣布为0.17.0仍然是湿墨水版本的0.17.0

If you are running Anaconda / conda package-manager for python, check:如果您正在为 python 运行Anaconda / conda package-manager,请检查:

$ conda search —all scikit-learn and $ conda search —all scikit-learn

$ conda depends scikit-learn to verify any newly added dependencies $ conda depends scikit-learn来验证任何新添加的依赖项

$ conda create -n (test-0-17-0-sklearn) scikit-learn for creating a new, separate, conda -named / -controlled environment for running python altogether with a sure sklearn ver. $ conda create -n (test-0-17-0-sklearn) scikit-learn创建一个新的,独立的, conda -named / -controlled与肯定sklearn版本完全运行Python环境。 0.17.0 for your further DEV/TEST 0.17.0 为您进一步的开发/测试

A: In any case, wrap the import into a try: { ... } except: { ... } A:无论如何,将导入包装成try: { ... } except: { ... }

try:
    from sklearn.ensemble import VotingClassifier
except:
    try:
        import sklearn
        print "WARNING: [VotingClassifier] not available\n",
              "WARNING: [import sklearn] reports version: ",
              sklearn.__version__, "\n"+60*"|"
    except:
        print "WARNING: impossible to [import sklearn] at all\n",
              60*"|"

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 无法从 sklearn.ensemble 导入任何内容 - Cannot import anything from sklearn.ensemble 可以在sklearn.ensemble中使用不同的分类器吗? - Is it possible to use different classifiers in sklearn.ensemble? 检查来自 sklearn.ensemble 的模型是否已适合数据 - Check if model from sklearn.ensemble has been fitted to data 导入 sklearn.ensemble 时收到错误 - Receiving error when I am importing sklearn.ensemble 从 sklearn.ensemble 导入时出现导入错误? - IMPORT ERROR when importing from sklearn.ensemble? 输入适用于某些sklearn模型,但不适用于sklearn.linear和sklearn.ensemble中的其他模型 - Inputs working with some sklearn models but not other models in sklearn.linear and sklearn.ensemble Pyinstaller和sklearn.ensemble:'ModuleNotFoundError:没有名为'sklearn.neighbors.quad_tree'的模块[2760]' - Pyinstaller and sklearn.ensemble: 'ModuleNotFoundError: No module named 'sklearn.neighbors.quad_tree' [2760]' python warnings.filterwarnings 不会忽略“import sklearn.ensemble”中的 DeprecationWarning - python warnings.filterwarnings does not ignore DeprecationWarning from 'import sklearn.ensemble' Python Ensemble VotingClassifier用于回归 - Python Ensemble VotingClassifier for regression sklearn.ensemble中的python特征选择特征重要性方法在多次运行中给出不一致的结果 - python feature selection feature importance method from sklearn.ensemble gives inconsistent results in multiple runs
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM