【问题标题】:How does TextBlob calculate sentiment polarity? How can I calculate a value for sentiment with machine learning classifier?TextBlob 如何计算情绪极性?如何使用机器学习分类器计算情绪值?
【发布时间】:2018-12-15 00:15:29
【问题描述】:

TextBlob 如何计算情绪极性的经验值。我使用了朴素贝叶斯,但它只是预测它是积极的还是消极的。我怎样才能像 TextBlob 那样计算情绪值?

【问题讨论】:

    标签: python python-3.x machine-learning sentiment-analysis textblob


    【解决方案1】:

    这是来自网站的示例:https://textblob.readthedocs.io/en/dev/quickstart.html#sentiment-analysis

    text1 = TextBlob("Today is a great day, but it is boring")
    text1.sentiment.polarity
    # You can derive the sentiment based on the polarity.
    

    这是我如何在推文情绪中使用 TextBlob 的示例代码:

    from textblob import TextBlob
    ### My input text is a column from a dataframe that contains tweets. 
    
    def sentiment(x):
        sentiment = TextBlob(x)
        return sentiment.sentiment.polarity
    
    tweetsdf['sentiment'] = tweetsdf['processed_tweets'].apply(sentiment)
    tweetsdf['senti'][tweetsdf['sentiment']>0] = 'positive'
    tweetsdf['senti'][tweetsdf['sentiment']<0] = 'negative'
    tweetsdf['senti'][tweetsdf['sentiment']==0] = 'neutral'
    

    根据极性和句子的真实发音,我最终得出了上述逻辑。请注意,某些推文可能并非如此。

    我个人发现 vader 情绪复合分数更有意义,这样我就可以根据复合分数和推文文本计算出积极、消极和中性情绪的范围,而不是仅仅为所有具有极性的文本分配积极情绪>0

    【讨论】:

      【解决方案2】:

      您的问题需要更清楚。您是在谈论创建自己的代码库来计算情绪吗?

      TextBlob 执行 NLP 任务,如标记化、情感分析、POS 标记等。 请参阅source code,了解如何计算情绪极性和主观性。

      您使用 TextBlob 或 Vader 计算情绪。根据极性和主观性,您确定它是正面文本还是负面或中性文本。对于TextBlog,如果极性>0,则认为是正的,

      然后您根据您的情绪(正面、负面、中性)训练分类器并继续进行预测。

      【讨论】:

      • 源代码什么也没显示;这很可能是问题所在。 TextBlob 似乎是一个基于价的模型,如果在这里有一个清晰的例子就好了。
      猜你喜欢
      • 1970-01-01
      • 2023-03-19
      • 2016-08-12
      • 1970-01-01
      • 1970-01-01
      • 2019-08-17
      • 2019-10-06
      • 2017-10-07
      • 1970-01-01
      相关资源
      最近更新 更多