【发布时间】:2016-08-13 08:44:06
【问题描述】:
我正在尝试复制 Go Et Al。 Twitter 情绪分析可以在这里找到http://help.sentiment140.com/for-students 我遇到的问题是功能数量为 364464。我目前正在使用 nltk 和 nltk.NaiveBayesClassifier 来执行此操作,其中推文包含 1,600,000 条推文的复制并且存在极性:
for tweet in tweets:
tweet[0] = extract_features(tweet[0], features)
classifier = nltk.NaiveBayesClassifier.train(training_set)
# print "NB Classified"
classifier.show_most_informative_features()
print(nltk.classify.util.accuracy(classifier, testdata))
除了 extract_features 函数之外,一切都不需要很长时间
def extract_features(tweet, featureList):
tweet_words = set(tweet)
features = {}
for word in featureList:
features['contains(%s)' % word] = (word in tweet_words)
return features
这是因为它为每条推文创建了一个大小为 364,464 的字典来表示是否存在某些内容。
有没有一种方法可以在不减少本文所述特征数量的情况下更快或更高效?
【问题讨论】:
-
我想知道您为什么不想使用与论文中相同的技术。无论如何,您可以采取的基本 NLP 步骤包括:删除停用词、进行 tfidf 矢量化并删除不太常见或非常常见的词......这些也会删除特征,但只是以不同的方式。正如我所说,我不太确定你想做什么。
-
如您所想,我遇到了内存问题,但我设法解决了它。感谢回复
标签: python twitter nltk sentiment-analysis