Classification of text documents is a simple task with scikit-learn but there isn't a clean support of that in NLTK, also there are samples for doing that in hard way like this. I want to preprocess with NLTK and classify with sckit-learn and I found SklearnClassifier in NLTK, but there is a little problem.
In scikit-learn everything is OK:
from sklearn.naive_bayes import MultinomialNB
from sklearn.multiclass import OneVsRestClassifier
X_train = [[0, 0], [0, 1], [1, 1]]
y_train = [('first',), ('second',), ('first', 'second')]
clf = OneVsRestClassifier(MultinomialNB())
clf.fit(X_train, y_train)
print clf.classes_
The result is ['first' 'second']
and it's my expectation. But when I try to use same code in NLTK:
from nltk.classify import SklearnClassifier
X_train = [{'a': 1}, {'b': 1}, {'c': 1}]
y_train = [('first',), ('second',), ('first', 'second')]
clf = SklearnClassifier(OneVsRestClassifier(MultinomialNB()))
clf.train(zip(X_train, y_train))
print clf.labels()
The result is [('first',), ('second',), ('first', 'second')]
and it isn't the proper one. Is there any solution?