雖然我想運行下面的代碼的最後一位,但我得到一個錯誤,我無法弄清楚爲什麼。Python培訓和測試錯誤
import random
combined_list = h_sub_text + s_sub_text
print(len(combined_list))
random.shuffle(combined_list)
training_part = int(len(combined_list) * .7)
print(len(combined_list))
training_set = combined_list[:training_part]
test_set = combined_list[training_part:]
print (len(train_set))
print (len(test_set))
import nltk.classify.util
from nltk.classify import NaiveBayesClassifier
classifier = NaiveBayesClassifier.train(train_set)
accuracy = nltk.classify.util.accuracy(classifier, test_set)
print("Accuracy is: ", accuracy * 100)
我得到這個錯誤:
ValueError Traceback (most recent call last)
<ipython-input-57-151936e75238> in <module>()
2 from nltk.classify import NaiveBayesClassifier
----> 4 classifier = NaiveBayesClassifier.train(training_set)
C:\Program Files (x86)\Anaconda3\lib\site-packages\nltk\classify\naivebayes.py in train(cls, labeled_featuresets, estimator)
--> 194 for featureset, label in labeled_featuresets:
195 label_freqdist[label] += 1
196 for fname, fval in featureset.items():
ValueError: too many values to unpack (expected 2)
在此先感謝。
將'train_set'替換爲' training_set'? 'train_set'在您提供的代碼中沒有定義。 – MervS
對不起,它的「NaiveBayesClassifier.train(training_set)」。在錯誤中它顯示了正確的對象。 – metalmks