0
votes

I am trying to save my trained Naive Bayes classifier in python. I've followed previous, similar questions to no avail. I'm kind of new to Python and don't really understand what is wrong, I've created and trained my classifier as per the NLTK book. How can I save this model to work on it later?

This is the error I've been stuck with:

picklingError: Can't pickle <class 'generator'>: attribute lookup generator on builtin failed

Currently I have:

classifier = nltk.NaiveBayesClassifier.train(train_set)
saveClassifier(classifier)

def saveClassifier(classifier):
        with open('cp_model.pkl', 'w') as f:
            dump(classifier, f)

Any help at all would be appreciated, I've literally been trying to fix this for hours.

Thanks.

1

1 Answers

0
votes

EDITED: I experimented a bit with this and I concluded that your code works perfectly when tried with the latest stable version of nltk on a valid dataset. So I would suggest you either update/reinstall your library or check that your dataset is a valid one. A valid dataset has to be a list of tuples (featureset,label).