我正在尝试理解如何从我得到的分数中构建一个甜甜圈图或饼图。下面是我的代码
from nltk.sentiment.vader import SentimentIntensityAnalyzer
paragraph = "I loved the movie"
sid = SentimentIntensityAnalyzer()
ss = sid.polarity_scores(paragraph)
print(ss)
if ss["compound"] >= 0.5:
print("positive")
elif ss["compound"] <= -0.5:
print("negative")
else:
print("neutral")
# myresults
{'neg': 0.033, 'neu': 0.834, 'pos': 0.132, 'compound': 0.9936}
positive如何使用复合分数将所有这些值计算成百分比?现在我只能给它一个正面、中性或负面的标签,但我想要基于复合分数的所有值的分解。对于此示例,正面分数应为99%,而不是61.2%中性、0%负面和38.8%正面
发布于 2018-10-15 04:45:44
您有ss = {'neg': 0.033, 'neu': 0.834, 'pos': 0.132, 'compound': 0.9936},并且希望有来自neg、neu和pos的值的饼图。如果我错了,请纠正我。
尝尝这个
labels = ['negative', 'neutral', 'positive']
sizes = [ss['neg'], ss['neu'], ss['pos']]
plt.pie(sizes, labels=labels, autopct='%1.1f%%') # autopct='%1.1f%%' gives you percentages printed in every slice.
plt.axis('equal') # Ensures that pie is drawn as a circle.
plt.show()https://stackoverflow.com/questions/52804788
复制相似问题