Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Sklearn error when trying to call a new classifier - Python 3.4

Whenever I try to call a new classifier I get the same error...

Here's my code:

from nltk.classify.scikitlearn import SklearnClassifier
from sklearn.naive_bayes import BernoulliNB

BernoulliNB_classifier = SklearnClassifier(BernoulliNB())

Here's the error:

Traceback (most recent call last):
File "<input>", line 1, in <module>
File "C:\Python34\lib\site-packages\nltk\classify\scikitlearn.py", line 69, in __init__
self._encoder = LabelEncoder()
NameError: name 'LabelEncoder' is not defined

When I look at the documentation that's exactly how it should be called (see http://www.nltk.org/api/nltk.classify.html)

Plus, it works on Python 2.7.

NB: I tried with the multinomial naive bayes, the support vector machines and many other algos, it returns the same error.

like image 630
Charles Avatar asked Aug 06 '16 21:08

Charles


1 Answers

try restarting the kernel, worked for me

like image 196
rutvick pisal Avatar answered Oct 19 '22 12:10

rutvick pisal