def word_feats(words):
return dict([(word, True) for word in words])
for tweet in negTweets:
words = re.findall(r"[\w']+|[.,!?;]", tweet) #splits the tweet into words
negwords = [(word_feats(words), 'neg')] #tag the words with feature
negfeats.append(negwords) #add the words to the feature list
for tweet in posTweets:
words = re.findall(r"[\w']+|[.,!?;]", tweet)
poswords = [(word_feats(words), 'pos')]
posfeats.append(poswords)
negcutoff = len(negfeats)*3/4 #take 3/4ths of the words
poscutoff = len(posfeats)*3/4
trainfeats = negfeats[:negcutoff] + posfeats[:poscutoff] #assemble the train set
testfeats = negfeats[negcutoff:] + posfeats[poscutoff:]
classifier = NaiveBayesClassifier.train(trainfeats)
print 'accuracy:', nltk.classify.util.accuracy(classifier, testfeats)
classifier.show_most_informative_features()
を解凍する必要以上1つの値このコードを実行しているとき、私は、エラーが来ている...PythonのNLTK Classifier.train(trainfeats)...とValueError:
File "C:\Python27\lib\nltk\classify\naivebayes.py", line 191, in train
for featureset, label in labeled_featuresets:
ValueError: need more than 1 value to unpack
を、次のエラーを取得していますクラシファイア= NaiveBayesClassifier.train(trainfeats)の行から、私はなぜそうはわかりません。私は前にこのようなことをしていましたが、私の訓練の継ぎ目はそれと同じ形式になっています...フォーマットのサンプルは以下にリストされています...
[[({'真:'、 'true'、 'true'、 'pos')]]]
私の他の値は何ですか? trainfeatsはクラシファイアを作成する必要がありますか? は@Pruneによってコメントが正しいとテキスト
カッコには大カッコが2つあります。唯一の要素がタプルだけのリストであるリストです。そのタプルには辞書と文字列が含まれています。おそらくあなたはラッパーが多すぎるので、アンパックは1つのアイテムだけを表示します。 – Prune