python - 在 Python 中根据 Textblob 的极性获取正面和负面的单词(情感分析)

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

我有一个文本 blob,其中如果极性 > 0,则将文本分类为正,如果 = 0,则将文本分类为中性,如果 < 0,则将文本分类为负。 我如何获得将其分类为积极、消极或中性的词语?

最佳答案

希望以下代码对您有所帮助:

from textblob import TextBlob
from textblob.sentiments import NaiveBayesAnalyzer
import nltk
nltk.download('movie_reviews')
nltk.download('punkt')

text          = "I feel the product is so good" 

sent          = TextBlob(text)
# The polarity score is a float within the range [-1.0, 1.0]
# where negative value indicates negative text and positive
# value indicates that the given text is positive.
polarity      = sent.sentiment.polarity
# The subjectivity is a float within the range [0.0, 1.0] where
# 0.0 is very objective and 1.0 is very subjective.
subjectivity  = sent.sentiment.subjectivity

sent          = TextBlob(text, analyzer = NaiveBayesAnalyzer())
classification= sent.sentiment.classification
positive      = sent.sentiment.p_pos
negative      = sent.sentiment.p_neg

print(polarity,subjectivity,classification,positive,negative)

关于python - 在 Python 中根据 Textblob 的极性获取正面和负面的单词(情感分析),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49731478/

相关文章:

python - 如何根据列表索引过滤 glom 中的列表?

python - 使用 VBA 运行 .exe

python - 从 () 中提取特定信息的最简单方法是什么?

来自一系列图像的python 16位灰度视频

python - winpdb 不适用于 python 3.3

python - 使用模式在 python 中版本字符串

python - 有没有比循环 numpy 数组更快的方法?

python - 做点积时的 NumPy 精度

python-3.x - 剪辑有什么作用?当他们将其用于测试集时

Python循环错误计数器