如何获得情感分数?
How to get the score of sentiments?
我正在使用 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 或任何其他格式的分数
您可以执行以下操作: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
您还可以将原生的 texblob 功能与您自己的分类器结合使用:
blob = TextBlob('I feel amazing!', classifier=cl)
print (blob.sentiment.polarity)
输出:
0.7500000000000001
我正在使用 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 或任何其他格式的分数
您可以执行以下操作: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
您还可以将原生的 texblob 功能与您自己的分类器结合使用:
blob = TextBlob('I feel amazing!', classifier=cl)
print (blob.sentiment.polarity)
输出: 0.7500000000000001