代码之家  ›  专栏  ›  技术社区  ›  Mohd Maaz Giri

如何获得情感分数?

  •  -2
  • Mohd Maaz Giri  · 技术社区  · 6 年前

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

    2 回复  |  直到 6 年前
        1
  •  1
  •   Jeril    6 年前

    您可以执行以下操作: 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
  •  1
  •   Stein    6 年前

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

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

    输出: 0.7500000000000001