我正在使用nltk書籍 - 自然語言處理與Python(2009)和看樸素貝葉斯分類器。特別是,在我的版本中,Pg 228上的示例6-3。 訓練集是電影評論。Python nltk樸素貝葉斯似乎並不工作
classifier = nltk.NaiveBayesClassifier.train(train_set)
我偷看了最翔實的特點 -
classifier.show_most_informative_features(5)
,我得到「優秀」,「花木蘭」和「奇妙」世界排名第一的人的句子中被標記「正」 。
所以,我嘗試以下方法 -
in1 = 'wonderfully mulan'
classifier.classify(document_features(in1.split()))
我得到 '負'。現在這沒有意義。這些應該是最重要的功能。
的document_features功能是直接從書中截取 - 「在整體語料庫2000個高頻詞」
def document_features(document):
document_words = set(document)
features = {}
for word in word_features:
features['contains(%s)' % word] = (word in document_words)
return features