4
這裏是我的代碼,其中i調用方法分類():find_features的類型錯誤:分類()缺少1所需位置參數: 'FEATURESET'
def sentiment(text):
feats = find_features(text)
return voted_classifier.classify(feats),voted_classifier.confidence(feats)
定義()方法:
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是:
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]
(注:我在Ubuntu 14.04做使用Python 3.4的Twitter情感分析,NLTK)