Reputation: 31
I am trying to implement multiple learning classifiers in python. I have 5 random forest classifiers in the code but now I am not able to import the VotingClassifier
function from sklearn.ensemble
.
When I write this:
from sklearn.ensemble import VotingClassifier
the error says:
ImportError: cannot import name VotingClassifier
How can I fix this?
Upvotes: 2
Views: 7032
Reputation:
I am the person who implemented the VotingClassifier
in scikit-learn. Sorry for the confusion, I just stumbled upon the "examples" section in the scikit-learn 16.1 documentation. This is a little bit misleading, the VotingClassifier
is already implemented but will be in the next version of 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)
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. The mlxtend
package is a little "playground" of mine where I upload some examples and functions that I find useful at times.
Hope that helps!
Upvotes: 3
Reputation: 1
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
.
If you are running Anaconda / conda
package-manager for python, check:
$ conda search —all scikit-learn
and
$ conda depends scikit-learn
to verify any newly added dependencies
$ 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. 0.17.0 for your further DEV/TEST
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*"|"
Upvotes: 0