TypeError: classify() missing 1 required positional argument: 'featureset'
TypeError: classify() missing 1 required positional argument: 'featureset'
这是我调用方法 classify() 的代码:
def sentiment(text):
feats = find_features(text)
return voted_classifier.classify(feats),voted_classifier.confidence(feats)
find_features() 方法的定义:
def find_features(document):
words = word_tokenize(document)
features = {}
for w in word_features:
features[w] = (w in words)
return features
我得到错误:
TypeError: classify() missing 1 required positional argument: 'featureset'
其中的特征集是:
featuresets_f = open("pickled_algos/featuresets.pickle", "rb")
featuresets = pickle.load(featuresets_f)
featuresets_f.close()
random.shuffle(featuresets)
print(len(featuresets))
testing_set = featuresets[8000:]
training_set = featuresets[:8000]
(注意:我正在使用 Python 3.4 和 Ubuntu 14.04 上的 nltk 进行 Twitter 情绪分析)
我怀疑你没有训练你的分类器。请注意以下错误:
>>> from nltk import NaiveBayesClassifier # for example
>>> NaiveBayesClassifier.classify(feats)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: classify() missing 1 required positional argument: 'featureset'
你需要先训练它:
>>> classifier = NaiveBayesClassifier.train(training_set)
然后可以对特征进行分类:
>>> classifier.classify(feats) # feats == a dict of features
这是我调用方法 classify() 的代码:
def sentiment(text):
feats = find_features(text)
return voted_classifier.classify(feats),voted_classifier.confidence(feats)
find_features() 方法的定义:
def find_features(document):
words = word_tokenize(document)
features = {}
for w in word_features:
features[w] = (w in words)
return features
我得到错误:
TypeError: classify() missing 1 required positional argument: 'featureset'
其中的特征集是:
featuresets_f = open("pickled_algos/featuresets.pickle", "rb")
featuresets = pickle.load(featuresets_f)
featuresets_f.close()
random.shuffle(featuresets)
print(len(featuresets))
testing_set = featuresets[8000:]
training_set = featuresets[:8000]
(注意:我正在使用 Python 3.4 和 Ubuntu 14.04 上的 nltk 进行 Twitter 情绪分析)
我怀疑你没有训练你的分类器。请注意以下错误:
>>> from nltk import NaiveBayesClassifier # for example
>>> NaiveBayesClassifier.classify(feats)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: classify() missing 1 required positional argument: 'featureset'
你需要先训练它:
>>> classifier = NaiveBayesClassifier.train(training_set)
然后可以对特征进行分类:
>>> classifier.classify(feats) # feats == a dict of features