本文整理汇总了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)
示例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))