Lea*_*ner 5 python machine-learning python-3.x sentiment-analysis textblob
我有一个文本 blob,其中如果极性 > 0,我将文本分类为正,如果 = 0,则为中性,如果 < 0,则为负。我如何根据将其分类为正、负或中性来获得单词?
小智 5
我希望以下代码可以帮助您:
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)
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
4800 次 |
| 最近记录: |