I am trying to train the NLTK classifier to analyze moods and then save the classifier using pickle. A freshly trained classifier works great. However, if I load a saved classifier, the classifier either displays โpositiveโ or โnegativeโ for ALL examples.
I save the classifier using
classifier = nltk.NaiveBayesClassifier.train(training_set)
classifier.classify(words_in_tweet)
f = open('classifier.pickle', 'wb')
pickle.dump(classifier, f)
f.close()
and loading the classifier using
f = open('classifier.pickle', 'rb')
classifier = pickle.load(f)
f.close()
classifier.classify(words_in_tweet)
I have no mistakes. Any idea what the problem might be, or how to properly debug it?
source
share