使用朴素贝叶斯分类器的AWS Sentiment Analysis教程

时间:2016-11-02 20:04:34

标签: python hadoop sentiment-analysis amazon-emr naivebayes

我正在关注here的AWS Sentiment Analysis教程。

我遇到的问题是,分类器永远不会发现负面推文。它总是只显示正面和中性的,

kindle: positive     492
No match:              8

使用tweepy库获取数据集。我使用以下python代码作为映射器,

映射器代码:

#!/usr/bin/python
import cPickle as pickle
import nltk.classify.util
from nltk.classify import NaiveBayesClassifier
from nltk.tokenize import word_tokenize
import sys

sys.stderr.write("Started mapper.\n");


def word_feats(words):
    return dict([(word, True) for word in words])


def subj(subjLine):
    subjgen = subjLine.lower()
    # Replace term1 with your subject term
    subj1 = "kindle"
    if subjgen.find(subj1) != -1:
        subject = subj1
        return subject
    else:
        subject = "No match"
        return subject


def main(argv):
    classifier = pickle.load(open("classifier.p", "rb"))
    for line in sys.stdin:
        tolk_posset = word_tokenize(line.rstrip())
        d = word_feats(tolk_posset)
        subjectFull = subj(line)
        if subjectFull == "No match":
            print "LongValueSum:" + " " + subjectFull + ": " + "\t" + "1"
        else:
            print "LongValueSum:" + " " + subjectFull + ": " + classifier.classify(d) + "\t" + "1"


if __name__ == "__main__":
    main(sys.argv)

我可以阅读数据集上的否定推文,但本教程中的这个例子没有检测到。

如何在我的程序中查找和显示否定推文进行故障排除 - 我的映射器代码或分类器文件是否有问题?

0 个答案:

没有答案