DataFrame的真值不明确。使用a.empty,a.bool(),a.item(),a.any()或a.all()。

时间:2019-06-13 09:03:31

标签: python nltk naivebayes

我收到此错误 DataFrame的真值不明确。使用a.empty,a.bool(),a.item(),a.any()或a.all()。

import nltk 

def buildVocabulary(preprocessedTrainingSet):
    all_words = []

    for text in preprocessedTrainingSet:
        all_words.extend(text)

    wordlist = nltk.FreqDist(all_words)
    word_features = wordlist.keys()

    return word_features


def extract_features(text):
    text_words = set(text)
    features = {}
    for word in word_features:
        features['contains(%s)' % word] = (word in text_words)
    return features 

word_features = buildVocabulary(preprocessedTrainingSet)
trainingFeatures = nltk.classify.apply_features(extract_features,preprocessedTrainingSet)
NBayesClassifier = nltk.NaiveBayesClassifier.train(trainingFeatures)

DataFrame的真值不明确。使用a.empty,a.bool(),a.item(),a.any()或a.all()。

0 个答案:

没有答案