本文整理汇总了Python中helper.Helper.setFilteredTweet方法的典型用法代码示例。如果您正苦于以下问题:Python Helper.setFilteredTweet方法的具体用法?Python Helper.setFilteredTweet怎么用?Python Helper.setFilteredTweet使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类helper.Helper
的用法示例。
在下文中一共展示了Helper.setFilteredTweet方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: Helper
# 需要导入模块: from helper import Helper [as 别名]
# 或者: from helper.Helper import setFilteredTweet [as 别名]
import nltk
from helper import Helper
tweet = 'tono gendut jelek'
# print classifier.classify(extract_features(tweet.split()))
helper = Helper()
helper.setFilteredTweet('sentiment.dat')
training_set = nltk.classify.apply_features(helper.extract_features, helper.filtered_tweet)
# print helper.positive_value
# print helper.negative_value
# classifier = SvmClassifier.train(training_set)
classifier = nltk.NaiveBayesClassifier.train(training_set)
helper.save_model('sentiment-naivebayes.mdl', classifier)
# helper.save_model('sentiment-svm.mdl', classifier)
# classifier = helper.load_model('sentiment-naivebayes.mdl')
classic = helper.extract_features(tweet.split())
corpus_tag = helper.get_tag_from_corpus('sentiment.dat')
corpus_text = helper.get_text_from_corpus('sentiment.dat')
test_tag = []
for text in corpus_text:
result = classifier.classify(helper.extract_features(text.split()))
test_tag.append(result)
corpus_tag.reverse()
test_tag.reverse()
cm = nltk.ConfusionMatrix(corpus_tag, test_tag)
print cm.pp(sort_by_count=True, show_percents=True, truncate=9)
print classic
print classifier.classify(classic)
示例2: Helper
# 需要导入模块: from helper import Helper [as 别名]
# 或者: from helper.Helper import setFilteredTweet [as 别名]
import nltk
from helper import Helper
tweet = 'tono asik'
# print classifier.classify(extract_features(tweet.split()))
helper = Helper()
helper.setFilteredTweet('opinion.dat')
training_set = nltk.classify.apply_features(helper.extract_features_opinion, helper.filtered_tweet)
# print helper.positive_value
# print helper.negative_value
classifier = nltk.NaiveBayesClassifier.train(training_set)
# classifier = nltk.MaxentClassifier.train(training_set)
helper.save_model('opinion-naivebayes.mdl', classifier)
# helper.save_model('opinion-maxent.mdl', classifier)
# classifier = helper.load_model('opinion-maxent.mdl')
classic = helper.extract_features_opinion(tweet.split())
corpus_tag = helper.get_tag_from_corpus('opinion.dat')
corpus_text = helper.get_text_from_corpus('opinion.dat')
test_tag = []
for text in corpus_text:
result = classifier.classify(helper.extract_features_opinion(text.split()))
test_tag.append(result)
corpus_tag.reverse()
test_tag.reverse()
cm = nltk.ConfusionMatrix(corpus_tag, test_tag)
print cm.pp(sort_by_count=True, show_percents=True, truncate=9)
print classic
print classifier.classify(classic)