希望有人能帮上忙,因为这会把我逼疯的!
from nltk.classify import NaiveBayesClassifier as nbc
from nltk import word_tokenize
tokens = {'alpha', 'beta', 'gamma', 'delta'}
list_of_tuples = [({'alpha': 10, 'beta': 10, 'gamma': 0, 'delta': 0}, 'A'),
({'alpha': 0, 'beta': 0, 'gamma': 10, 'delta': 10}, 'B')]
classifier = nbc.train(list_of_tuples)
tests = ['alpha', 'beta', 'gamma', 'delta']
for test in tests:
features = {word: (int(word in word_tokenize(test))) for word in tokens}
print(test, " :: ", classifier.classify(features))
这给了我a,a,b,b,正如我所期望的。但是如果我做一个小小的改变-,伽马在第一个1:
list_of_tuples = [({'alpha': 10, 'beta': 10, 'gamma': 1, 'delta': 0}, 'A'),
({'alpha': 0, 'beta': 0, 'gamma': 10, 'delta': 10}, 'B')]
我仍然希望得到a,a,b,b。但是相反,我得到了b,b,b,b。有什么好处?
暂无答案!
目前还没有任何答案,快来回答吧!