1
votes

I'm using nltk with a scikit-learn classifier and the interface is throwing an error I cannot explain.

Here is a minimum working example:

import nltk
import sklearn

from sklearn.naive_bayes import MultinomialNB

nltk.classify.scikitlearn.SklearnClassifier(MultinomialNB())

This throws the error

name 'LabelEncoder' is not defined

Importing LabelEncoder (as suggested here) does not work – and it would be strange if it did. Looking at the source code of nltk.classify.scikitlearn, LabelEncoder should be loaded internally.

It seems this is problem of my local installation rather than the nltk or sklearn package. I'm out of ideas, though. Does anyone have an idea what might be going wrong here?

Versions:

nltk.__version__ '3.5'; 
sklearn.__version__ '0.24.0'; 
sys.version
'3.9.1 (default, Jan  8 2021, 17:17:43) [Clang 12.0.0 (clang-1200.0.32.28)]
What versions are you running of all these? Mine didn't throw an error; In [2]: nltk.__version__ Out[2]: '3.5' In [3]: sklearn.__version__ Out[3]: '0.24.0' In [4]: import sys; sys.version Out[4]: '3.9.0 (default, Dec 9 2020, 00:55:33) \n[Clang 12.0.0 (clang-1200.0.32.27)]'Frank
Same versions (except sys), added versions directly to questionaltabq
I was able to fix this. It seems to have been a homebrew issue. Updating, upgrading, running brew doctor, and cleanup plus a system restart fixed the error.altabq