本文整理汇总了Python中classifier.Classifier.classifier方法的典型用法代码示例。如果您正苦于以下问题:Python Classifier.classifier方法的具体用法?Python Classifier.classifier怎么用?Python Classifier.classifier使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类classifier.Classifier
的用法示例。
在下文中一共展示了Classifier.classifier方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: main
# 需要导入模块: from classifier import Classifier [as 别名]
# 或者: from classifier.Classifier import classifier [as 别名]
def main():
me=Classifier()
feature_counter=Counter()
feature_set=pickle.load(open('validation_set.pkl', 'rb'))
feature_set_labels=[]
for tweet, rating in feature_set:
print rating
try:
float(rating)
except:
continue
if float(rating)>0:
label='positive'
elif float(rating)<0:
label='negative'
else:
label='neutral'
feature_set_labels.append((tweet, label))
feature_list=chain.from_iterable([word_tokenize(process_tweet(tweet)) for tweet, sentiment in feature_set_labels])
for feat in feature_list:
feature_counter[feat]+=1
me.feature_list=[feat for feat, count in feature_counter.most_common(1000)]
ts=[(me.extract_features(tweet), label) for tweet, label in feature_set]
print 'training Maxent'
me.classifier=MaxentClassifier.train(ts)
return me
示例2: main
# 需要导入模块: from classifier import Classifier [as 别名]
# 或者: from classifier.Classifier import classifier [as 别名]
def main():
me=Classifier()
feature_counter=Counter()
feature_set=pickle.load(open('undersampled_emoticon.pkl', 'rb'))
feature_list=chain.from_iterable([word_tokenize(process_tweet(tweet)) for tweet, sentiment in feature_set])
for feat in feature_list:
feature_counter[feat]+=1
me.feature_list=[feat for feat, count in feature_counter.most_common(1000)]
ts=[(me.extract_features(tweet), label) for tweet, label in feature_set]
print 'training Maxent, algorithm CG'
me.classifier=MaxentClassifier.train(ts)
return me