当前位置: 首页>>代码示例>>Python>>正文


Python Classifier.extract_features方法代码示例

本文整理汇总了Python中classifier.Classifier.extract_features方法的典型用法代码示例。如果您正苦于以下问题:Python Classifier.extract_features方法的具体用法?Python Classifier.extract_features怎么用?Python Classifier.extract_features使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在classifier.Classifier的用法示例。


在下文中一共展示了Classifier.extract_features方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: main

# 需要导入模块: from classifier import Classifier [as 别名]
# 或者: from classifier.Classifier import extract_features [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
开发者ID:anov,项目名称:honors,代码行数:28,代码来源:maxent_turk.py

示例2: main

# 需要导入模块: from classifier import Classifier [as 别名]
# 或者: from classifier.Classifier import extract_features [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
开发者ID:anov,项目名称:honors,代码行数:14,代码来源:maxent.py

示例3: Classifier

# 需要导入模块: from classifier import Classifier [as 别名]
# 或者: from classifier.Classifier import extract_features [as 别名]
		print "Extracting features and classifiying using Naive Bayes..."
		# save the training set and the classifier

		c = Classifier(word_features, tweets)

	elif CLASSIFIER_MADE:
		print "Reloading previously created classifier..."

		c = Classifier(	word_features=p.load('word_features'),
						tweets=p.load('tweets'),
						classifier=p.load('my_classifier'),
						show_count=False
						)

	print c.classifier.show_most_informative_features(32)

	# testing it out
	print "\ntesting out the classifier"
	ts = [
			"wonderful, everything is going wrong right now",
			"The movie wasn't that bad",
			"this is a very thought provoking book",
			"my new computer was expensive, but I'm much more productive now",
			"people like john are hard to deal with",
			"I'm not happy"
			]
	for tweet in ts:
		print c.classifier.classify(c.extract_features(tweet.split())), '------>', tweet

	print "END {0}".format(datetime.now())
开发者ID:tomzaragoza,项目名称:sentiment,代码行数:32,代码来源:sentiment.py


注:本文中的classifier.Classifier.extract_features方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。