Error Message:
Traceback (most recent call last): File "/Users/ABHINAV/Documents/test2.py", line 58, in classifier = NaiveBayesClassifier.train(trainfeats) File "/Library/Python/2.7/site-packages/nltk/classify/naivebayes.py", line 194, in train for featureset, label in labeled_featuresets: ValueError: too many values to unpack [Finished in 17.0s with exit code 1]
I am getting this error while I am trying to implement Naive Bayes on a set of data. Here is the code for that:
import nltk.classify.util
from nltk.classify import NaiveBayesClassifier
from nltk.corpus import movie_reviews
def word_feats(words):
return dict([(word, True) for word in words])
negids = movie_reviews.fileids('neg')
posids = movie_reviews.fileids('pos')
negfeats = [(word_feats(movie_reviews.words(fileids=[f])), 'neg') for f in negids]
posfeats = [(word_feats(movie_reviews.words(fileids=[f])), 'pos') for f in posids]
negcutoff = len(negfeats)*3/4
poscutoff = len(posfeats)*3/4
trainfeats=[('good'),('pos'),
('quick'),('pos'),
('easy'),('pos'),
('big'),('pos'),
('iterested'),('pos'),
('important'),('pos'),
('new'),('pos'),
('patient'),('pos'),
('few'),('neg'),
('bad'),('neg'),
]
test=[
('general'),('pos'),
('many'),('pos'),
('efficient'),('pos'),
('great'),('pos'),
('interested'),('pos'),
('top'),('pos'),
('easy'),('pos'),
('big'),('pos'),
('new'),('pos'),
('wonderful'),('pos'),
('important'),('pos'),
('best'),('pos'),
('more'),('pos'),
('patient'),('pos'),
('last'),('pos'),
('worse'),('neg'),
('terrible'),('neg'),
('awful'),('neg'),
('bad'),('neg'),
('minimal'),('neg'),
('incomprehensible'),('neg'),
]
classifier = NaiveBayesClassifier.train(trainfeats)
print 'accuracy:', nltk.classify.util.accuracy(classifier, test)
classifier.show_most_informative_features()