对于如何保存训练有素的分类器,我有点困惑。例如,每次我想使用它时重新训练一个分类器显然真的很糟糕而且很慢,我如何保存它并在需要时再次加载它?代码如下,提前感谢您的帮助。我正在使用带有 NLTK 朴素贝叶斯分类器的 Python。
classifier = nltk.NaiveBayesClassifier.train(training_set)
# look inside the classifier train method in the source code of the NLTK library
def train(labeled_featuresets, estimator=nltk.probability.ELEProbDist):
# Create the P(label) distribution
label_probdist = estimator(label_freqdist)
# Create the P(fval|label, fname) distribution
feature_probdist = {}
return NaiveBayesClassifier(label_probdist, feature_probdist)