【发布时间】:2012-04-01 04:56:10
【问题描述】:
我在这里的第一篇文章! 我在使用 nltk NaiveBayesClassifier 时遇到问题。我有一个包含 7000 个项目的训练集。每个训练项目都有 2 或 3 个世界的描述和一个代码。我想将代码用作类的标签,将描述的每个世界用作特征。 一个例子:
“我叫奥巴马”,001 ...
训练集 = {[feature['My']=True,feature['name']=True,feature['is']=True,feature[Obama]=True], 001}
不幸的是,使用这种方法,训练程序 NaiveBayesClassifier.train 最多使用 3 GB 的内存。 我的方法有什么问题? 谢谢!
def document_features(document): # feature extractor
document = set(document)
return dict((w, True) for w in document)
...
words=set()
entries = []
train_set= []
train_length = 2000
readfile = open("atcname.pl", 'r')
t = readfile.readline()
while (t!=""):
t = t.split("'")
code = t[0] #class
desc = t[1] # description
words = words.union(s) #update dictionary with the new words in the description
entries.append((s,code))
t = readfile.readline()
train_set = classify.util.apply_features(document_features, entries[:train_length])
classifier = NaiveBayesClassifier.train(train_set) # Training
【问题讨论】:
标签: python nltk bayesian classification