使用 VADER 进行情感分析

2024 年 8 月 29 日 | 阅读 3 分钟

情感分析是一个‘计算确定’一段文本是积极、中性还是消极的过程。它也被称为意见挖掘。这个过程确定段落中的句子是消极、积极还是中性。

  • 商业:营销公司利用它来制定策略,了解客户对产品和品牌的感受,他们如何响应营销活动和产品发布,以及为什么一些消费者不购买某些产品。
  • 政治:它被用于政治领域,以追踪政治观点,并在政府层面检测言行之间的一致性或不一致性。它还可以用于预测选举结果。
  • 公众活动:情感分析也用于分析社会现象,并发现潜在的危险情况。

安装 vaderSentiment

我们可以使用以下命令安装 vaderSentiment 模块

VADER 情感分析

Valence Aware Dictionary and Sentiment Reasoner (VADER) 是一种字典,它使用基于规则的情感分析工具。它尤其适用于社交媒体情感。VADER 使用情感词典的混合,该词典是语言特征(例如,单词)的列表,这些语言特征根据其语义方向被标记为消极或积极。VADER 不仅告诉我们积极性或消极性的得分,还告诉我们情感有多积极和多消极。

代码

输出

The 1st statement :
The overall sentiment dictionary is:  {'neg': 0.0, 'neu': 1.0, 'pos': 0.0, 'compound': 0.0}
The sentence has been rated as  0.0 % Negative
The sentence has been rated as  100.0 % Neutral
The sentence has been rated as  0.0 % Positive
The sentence Overall Rated As  It is Neutral

 The 2nd Statement :
The overall sentiment dictionary is:  {'neg': 0.0, 'neu': 1.0, 'pos': 0.0, 'compound': 0.0}
The sentence has been rated as  0.0 % Negative
The sentence has been rated as  100.0 % Neutral
The sentence has been rated as  0.0 % Positive
The sentence Overall Rated As  It is Neutral

 The 3rd Statement :
The overall sentiment dictionary is:  {'neg': 0.0, 'neu': 0.457, 'pos': 0.543, 'compound': 0.8934}
The sentence has been rated as  0.0 % Negative
The sentence has been rated as  45.7 % Neutral
The sentence has been rated as  54.300000000000004 % Positive
The sentence Overall Rated As   It is Positive

复合得分是通过对所有词典评分进行求和而计算出来的,这些评分在 -1(最极端消极)或 +1(最极端积极)之间进行了归一化。

积极情感:(复合得分 > = 0.0.05);

中性情感:(复合得分 > -0.05);

消极情感:(复合得分 = 0.0.05);。