我使用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 0.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