Python情感分类

标签 python nltk sentiment-analysis

您好,我正在尝试使用情感分类器包对某些文本文件进行分类。以下程序适用于单个句子,即,

from senti_classifier import senti_classifier
sentences = ['i love u']
pos_score, neg_score = senti_classifier.polarity_scores(sentences)
print pos_score, neg_score

但是,当按照以下方式使用 xls 文件对每个记录进行分类时,正分和负分的结果均为 0.0。 请帮帮我。

import openpyxl
from senti_classifier import senti_classifier
wb = openpyxl.load_workbook('sentiment2.xlsx')
sheet = wb.active
sheet.columns[0]
for cellObj in sheet.columns[0]:
    sentences = cellObj.value
    print(sentences)
    pos_score, neg_score = senti_classifier.polarity_scores(sentences)
    print pos_score, neg_score

最佳答案

senti_classifier.polarity_scores() function需要一个字符串列表作为参数,但您传递的是单个字符串。将其放入列表中:

pos_score, neg_score = senti_classifier.polarity_scores([sentences])

关于Python情感分类,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38214855/

相关文章:

Python 调用 "self.property"和创建返回 "self.property"的方法有什么区别?

python - 如何使用 BeautifulSoup 寻找值(value)

python - 生产环境中的 NLTK?

web-applications - 情感分析使推文与搜索查询匹配并进行分析

python - glob 生成器的类型注释

python - 添加 '=' 对 Python 中的位运算符有什么作用? (即 '<<=' 而不是 '<<' )

python-3.x - 无法预测表情符号的情绪

python - 解析 LaTex 作者标签以提取作者姓名

machine-learning - Vowpal Wabbit 输出的解释

algorithm - 寻找产品评论数据集