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


Python Classifier.getClass方法代码示例

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


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

示例1: len

# 需要导入模块: from Classifier import Classifier [as 别名]
# 或者: from Classifier.Classifier import getClass [as 别名]
positiveData = trainingData[:320]
negativeData = trainingData[320:]

posFactor = len(positiveData)//10
negFactor = len(negativeData)//10

avgAccuracy = 0

for i in range(10):
	testSet = positiveData[i*posFactor:i*posFactor+posFactor] + negativeData[i*negFactor:i*negFactor+negFactor]
	trainingSet = positiveData[:i*posFactor]+positiveData[i*posFactor+posFactor:]+negativeData[:i*negFactor]+negativeData[i*negFactor+negFactor:]
	
	try:
		x = pickle.load(open("model"+str(i)+".pickle", "rb"))
	except (OSError, IOError) as e:
		x = Classifier(trainingSet, vocabulary)
		pickle.dump(x, open("model"+str(i)+".pickle", "wb"))
	right = 0
	wrong = 0
	for reviewItem in testSet:
		(reviewClass, review) = reviewItem.split('\t')
		if reviewClass == x.getClass(review):
			right = right + 1
		else:
			wrong = wrong + 1
	print('Accuracy for TestSet',(i+1), '=',right/(right+wrong))
	avgAccuracy = avgAccuracy + right/(right+wrong)

print('Avg Accuracy =',avgAccuracy/10)
开发者ID:Suraj-Yadav,项目名称:Sentiment-Analysis,代码行数:31,代码来源:CrossValid.py

示例2: open

# 需要导入模块: from Classifier import Classifier [as 别名]
# 或者: from Classifier.Classifier import getClass [as 别名]
from Classifier import Classifier

vocabularyFile = open("../Step_6/vocabulary.txt", mode='r')
vocabulary = vocabularyFile.read().splitlines()
trainingFile = open("../Step_2/data.txt", mode='r')
trainingData = trainingFile.read().splitlines()

x = Classifier(trainingData, vocabulary)
review = input('Enter a Review\n')
print(x.getClass(review))
开发者ID:Suraj-Yadav,项目名称:Sentiment-Analysis,代码行数:12,代码来源:tester.py


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