【发布时间】:2012-04-18 12:19:06
【问题描述】:
对于如何保存经过训练的分类器,我有些困惑。例如,每次我想使用它时重新训练一个分类器显然真的很糟糕而且很慢,我如何保存它并在需要时再次加载它?代码如下,提前感谢您的帮助。我正在使用带有 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)
【问题讨论】:
-
您是否要求某种持久性策略?与保存到数据库、文件并再次加载一样?您可以只腌制数据并稍后再次加载。
标签: python machine-learning classification nltk naivebayes