我试图获得准确度,召回率和F-措施的积极和消极预测情绪分析。 我使用的python 3.6如下:
import nltk
from nltk.tokenize import word_tokenize
# Trainng data
train = [('I love this sandwich.', 'pos'),
('This is an amazing place!', 'pos'),
('I feel very good about these beers.', 'pos'),
('This is my best work.', 'pos'),
("What an awesome view", 'pos'),
('I do not like this restaurant', 'neg'),
('I am tired of this stuff.', 'neg'),
("I can't deal with this", 'neg'),
('He is my sworn enemy!', 'neg'),
('My boss is horrible.', 'neg') ]
# Test data
test = [('The beer was good.', 'pos'),
('I do not enjoy my job', 'neg'),
("I ain't feeling dandy today.", 'neg'),
("I feel amazing!", 'pos'),
('Gary is a friend of mine.', 'pos'),
("I can't believe I'm doing this.", 'neg') ]
# Tokenize Training words
Training_words = set(word.lower() for passage in train for word in word_tokenize(passage[0]))
# Training feature sets
training_set = [({word: (word in word_tokenize(x[0])) for word in Training_words}, x[1]) for x in train]
# Tokenize Test words
Test_words = set(word.lower() for passage in test for word in word_tokenize(passage[0]))
# Test feature sets
test_set= [({word: (word in word_tokenize(x[0])) for word in Test_words}, x[1]) for x in test]
# Naive Bayes classifier
classifier = nltk.NaiveBayesClassifier.train(training_set)
# Informative Features
classifier.show_most_informative_features()
# print the accuracy
print("accuracy %",(nltk.classify.accuracy(classifier, test_set))*100)
上面的代码显示了naivebayes分类器的信息特性和准确性。 我尝试了下面的代码来获得它的精确性、召回率以及对正面和负面预测的F度量。在
^{pr2}$我需要你的hep。。在
目前没有回答
相关问题 更多 >
编程相关推荐