I am having trouble pickling a naive bayes classifier trained via nltk. Here is the code I am using to save the classifier:
pickledfile=open('my_classifier.pickle','wb')
pickle.dump(classifier,pickledfile)
pickledfile.close()
This seems to work ok. However, when I try and load the pickled file using the following code:
f1=open('my_classifier.pickle')
classifier=pickle.load(f1)
f1.close()
I get an EOF error. I got this code straight from this question and it doesnt work for whatever reason for me: Save Naive Bayes Trained Classifier in NLTK. Let me know if you know what is going on with this.
cPickle
module worked for me. If it doesn't work either, try setting the protocol to 1:pickle.dump(classifier, pickledfile, 1)
– Suzana