gpt4 book ai didi

python - TextBlob 如何计算情感极性?如何使用机器学习分类器计算情绪值?

转载 作者:行者123 更新时间:2023-12-04 13:02:53 28 4
gpt4 key购买 nike

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

最佳答案

以下是该站点的示例: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'

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

我个人发现维德情绪复合分数更有意义,因此我可以根据复合分数和推文文本找出积极、消极和中性情绪的范围,而不是仅仅为极性 >0 的所有文本分配积极情绪

关于python - TextBlob 如何计算情感极性?如何使用机器学习分类器计算情绪值?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51209514/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com