我正在使用TextBlob
,我正在训练集上训练classifier
之后,我就能够成功获得分类输出了
请问我应该如何在训练数据中输入情感分数,以积极或消极的方式获取特定文本的分数
这是我尝试过的
from textblob import TextBlob
from textblob.classifiers import NaiveBayesClassifier
train = [
('I love this sandwich.', 'pos'),
('This is an amazing place!', 'pos'),
('I feel very good about these beers.', 'pos'),
('I do not like this restaurant', 'neg'),
('I am tired of this stuff.', 'neg'),
("I can't deal with this", 'neg'),
("My boss is horrible.", "neg")
]
cl = NaiveBayesClassifier(train)
cl.classify("I feel amazing!")
这是输出
'pos'
如何获得pos .7或其他任何格式的分数
答案 0 :(得分:1)
您可以执行以下操作:source here
>>> prob_dist = cl.prob_classify("I feel amazing!")
>>> prob_dist.max()
'pos'
>>> round(prob_dist.prob("pos"), 2)
0.63
>>> round(prob_dist.prob("neg"), 2)
0.37
答案 1 :(得分:1)
您还可以将本机texblob功能与您自己的分类器一起使用:
blob = TextBlob('I feel amazing!', classifier=cl)
print (blob.sentiment.polarity)
输出: 0.7500000000000001