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