【问题标题】:Python sentiment classificationPython情感分类
【发布时间】:2016-07-06 00:38:15
【问题描述】:

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

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

【问题讨论】:

    标签: python nltk sentiment-analysis


    【解决方案1】:

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

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2022-01-15
      • 2020-08-14
      • 1970-01-01
      • 2023-04-04
      • 2020-04-17
      • 2015-12-31
      • 2010-10-09
      • 2016-02-05
      相关资源
      最近更新 更多