本文整理汇总了Python中minicontest.contestClassifier函数的典型用法代码示例。如果您正苦于以下问题:Python contestClassifier函数的具体用法?Python contestClassifier怎么用?Python contestClassifier使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了contestClassifier函数的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: readCommand
#.........这里部分代码省略.........
options, otherjunk = parser.parse_args(argv)
if len(otherjunk) != 0: raise Exception('Command line input not understood: ' + str(otherjunk))
args = {}
# Set up variables according to the command line input.
print "Doing classification"
print "--------------------"
print "data:\t\t" + options.data
print "classifier:\t\t" + options.classifier
if not options.classifier == 'minicontest':
print "using enhanced features?:\t" + str(options.features)
else:
print "using minicontest feature extractor"
print "training set size:\t" + str(options.training)
if(options.data=="digits"):
printImage = ImagePrinter(DIGIT_DATUM_WIDTH, DIGIT_DATUM_HEIGHT).printImage
if (options.features):
featureFunction = enhancedFeatureExtractorDigit
else:
featureFunction = basicFeatureExtractorDigit
if (options.classifier == 'minicontest'):
featureFunction = contestFeatureExtractorDigit
elif(options.data=="faces"):
printImage = ImagePrinter(FACE_DATUM_WIDTH, FACE_DATUM_HEIGHT).printImage
if (options.features):
featureFunction = enhancedFeatureExtractorFace
else:
featureFunction = basicFeatureExtractorFace
elif(options.data=="pacman"):
printImage = None
if (options.features):
featureFunction = enhancedFeatureExtractorPacman
else:
featureFunction = basicFeatureExtractorPacman
else:
print "Unknown dataset", options.data
print USAGE_STRING
sys.exit(2)
if(options.data=="digits"):
legalLabels = range(10)
else:
legalLabels = ['Stop', 'West', 'East', 'North', 'South']
if options.training <= 0:
print "Training set size should be a positive integer (you provided: %d)" % options.training
print USAGE_STRING
sys.exit(2)
if options.smoothing <= 0:
print "Please provide a positive number for smoothing (you provided: %f)" % options.smoothing
print USAGE_STRING
sys.exit(2)
if options.odds:
if options.label1 not in legalLabels or options.label2 not in legalLabels:
print "Didn't provide a legal labels for the odds ratio: (%d,%d)" % (options.label1, options.label2)
print USAGE_STRING
sys.exit(2)
if(options.classifier == "mostFrequent"):
classifier = mostFrequent.MostFrequentClassifier(legalLabels)
elif(options.classifier == "naiveBayes" or options.classifier == "nb"):
classifier = naiveBayes.NaiveBayesClassifier(legalLabels)
classifier.setSmoothing(options.smoothing)
if (options.autotune):
print "using automatic tuning for naivebayes"
classifier.automaticTuning = True
else:
print "using smoothing parameter k=%f for naivebayes" % options.smoothing
elif(options.classifier == "perceptron"):
if options.data != 'pacman':
classifier = perceptron.PerceptronClassifier(legalLabels,options.iterations)
else:
classifier = perceptron_pacman.PerceptronClassifierPacman(legalLabels,options.iterations)
elif(options.classifier == "mira"):
if options.data != 'pacman':
classifier = mira.MiraClassifier(legalLabels, options.iterations)
if (options.autotune):
print "using automatic tuning for MIRA"
classifier.automaticTuning = True
else:
print "using default C=0.001 for MIRA"
elif(options.classifier == 'minicontest'):
import minicontest
classifier = minicontest.contestClassifier(legalLabels)
else:
print "Unknown classifier:", options.classifier
print USAGE_STRING
sys.exit(2)
args['agentToClone'] = options.agentToClone
args['classifier'] = classifier
args['featureFunction'] = featureFunction
args['printImage'] = printImage
return args, options
开发者ID:SoloistRoy,项目名称:CS188-Project5-Classifier,代码行数:101,代码来源:dataClassifier.py
示例2: range
MINICONTEST_PATH = "minicontest_output.pickle"
if __name__ == '__main__':
print "Loading training data"
rawTrainingData = samples.loadDataFile("digitdata/trainingimages", 5000,DIGIT_DATUM_WIDTH,DIGIT_DATUM_HEIGHT)
trainingLabels = samples.loadLabelsFile("digitdata/traininglabels", 5000)
rawValidationData = samples.loadDataFile("digitdata/validationimages", 100,DIGIT_DATUM_WIDTH,DIGIT_DATUM_HEIGHT)
validationLabels = samples.loadLabelsFile("digitdata/validationlabels", 100)
rawTestData = samples.loadDataFile("digitdata/testimages", TEST_SIZE,DIGIT_DATUM_WIDTH,DIGIT_DATUM_HEIGHT)
featureFunction = contestFeatureExtractorDigit
legalLabels = range(10)
classifier = minicontest.contestClassifier(legalLabels)
print "Extracting features..."
trainingData = map(featureFunction, rawTrainingData)
validationData = map(featureFunction, rawValidationData)
testData = map(featureFunction, rawTestData)
print "Training..."
classifier.train(trainingData, trainingLabels, validationData, validationLabels)
print "Validating..."
guesses = classifier.classify(validationData)
correct = [guesses[i] == validationLabels[i] for i in range(len(validationLabels))].count(True)
print str(correct), ("correct out of " + str(len(validationLabels)) + " (%.1f%%).") % (100.0 * correct / len(validationLabels))
print "Testing..."
guesses = classifier.classify(testData)
开发者ID:cenkt,项目名称:cs188-1,代码行数:29,代码来源:runMinicontest.py
注:本文中的minicontest.contestClassifier函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论