【发布时间】:2016-11-27 06:06:32
【问题描述】:
我正在使用 NLTK 测试情绪分析模型。我需要在分类器结果中添加一个混淆矩阵,如果可能的话,还要添加精度、召回率和 F-Measure 值。到目前为止,我只有准确性。 Movie_reviews 数据具有 pos 和 neg 标签。然而,为了训练分类器,我使用了与通常(句子、标签)结构不同格式的“特征集”。在通过“特征集”训练分类器后,我不确定是否可以使用 sklearn 中的confusion_matrix
import nltk
import random
from nltk.corpus import movie_reviews
documents = [(list(movie_reviews.words(fileid)), category)
for category in movie_reviews.categories()
for fileid in movie_reviews.fileids(category)]
random.shuffle(documents)
all_words = []
for w in movie_reviews.words():
all_words.append(w.lower())
all_words = nltk.FreqDist(all_words)
word_features = list(all_words.keys())[:3000]
def find_features(document):
words = set(document)
features = {}
for w in word_features:
features[w] = (w in words)
return features
featuresets = [(find_features(rev), category) for (rev, category) in documents]
training_set = featuresets[:1900]
testing_set = featuresets[1900:]
classifier = nltk.NaiveBayesClassifier.train(training_set)
print("Naive Bayes Algo accuracy percent:", (nltk.classify.accuracy(classifier, testing_set))*100)
【问题讨论】:
标签: scikit-learn nltk sentiment-analysis confusion-matrix