【问题标题】:How to get the score of sentiments?如何获得情绪分数?
【发布时间】:2019-02-04 08:15:28
【问题描述】:

我正在使用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 或任何其他格式的分数

【问题讨论】:

    标签: python nltk sentiment-analysis textblob


    【解决方案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
    

    【讨论】:

      【解决方案2】:

      您还可以将本机 texblob 功能与您自己的分类器一起使用:

      blob = TextBlob('I feel amazing!', classifier=cl)
      print (blob.sentiment.polarity)
      

      输出: 0.7500000000000001

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2021-04-19
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多