Save and Load testing classify Naive Bayes Classifier in NLTK in another method

后端 未结 1 1281
迷失自我
迷失自我 2021-01-06 12:14

I have try the code from here: Save Naive Bayes Trained Classifier in NLTK. I want to classify tweet into positive class or negative class. this is my code:

         


        
相关标签:
1条回答
  • 2021-01-06 13:15

    I don't have the environment setup to test out your code, but I have the feeling it's not right in the part where you save/load the pickle.

    Referring to the Storing Taggers section of the NLTK book, I would change your code and do it like this:

    def save_classifier(classifier):
       f = open('my_classifier.pickle', 'wb')
       pickle.dump(classifier, f, -1)
       f.close()
    
    def load_classifier():
       f = open('my_classifier.pickle', 'rb')
       classifier = pickle.load(f)
       f.close()
       return classifier
    

    Hope it helps.

    0 讨论(0)
提交回复
热议问题