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


Python samples.loadLabelsFile函数代码示例

本文整理汇总了Python中samples.loadLabelsFile函数的典型用法代码示例。如果您正苦于以下问题:Python loadLabelsFile函数的具体用法?Python loadLabelsFile怎么用?Python loadLabelsFile使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


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

示例1: readDigitData

def readDigitData(trainingSize=100, testSize=100):
    rootdata = "digitdata/"
    # loading digits data
    rawTrainingData = samples.loadDataFile(
        rootdata + "trainingimages", trainingSize, DIGIT_DATUM_WIDTH, DIGIT_DATUM_HEIGHT
    )
    trainingLabels = samples.loadLabelsFile(rootdata + "traininglabels", trainingSize)
    rawValidationData = samples.loadDataFile(
        rootdata + "validationimages", TEST_SET_SIZE, DIGIT_DATUM_WIDTH, DIGIT_DATUM_HEIGHT
    )
    validationLabels = samples.loadLabelsFile(rootdata + "validationlabels", TEST_SET_SIZE)
    rawTestData = samples.loadDataFile("digitdata/testimages", testSize, DIGIT_DATUM_WIDTH, DIGIT_DATUM_HEIGHT)
    testLabels = samples.loadLabelsFile("digitdata/testlabels", testSize)
    try:
        print "Extracting features..."
        featureFunction = dataClassifier.basicFeatureExtractorDigit
        trainingData = map(featureFunction, rawTrainingData)
        validationData = map(featureFunction, rawValidationData)
        testData = map(featureFunction, rawTestData)
    except:
        display("An exception was raised while extracting basic features: \n %s" % getExceptionTraceBack())
    return (
        trainingData,
        trainingLabels,
        validationData,
        validationLabels,
        rawTrainingData,
        rawValidationData,
        testData,
        testLabels,
        rawTestData,
    )
开发者ID:thomaschow,项目名称:cs188,代码行数:32,代码来源:classificationTestClasses.py

示例2: get_neuron_training_data

def get_neuron_training_data():
	training_data = samples.loadDataFile("digitdata/trainingimages", num_train_examples, 28, 28)
	training_labels = np.array(samples.loadLabelsFile("digitdata/traininglabels", num_train_examples))
	training_labels = training_labels == 3

	featurized_training_data = np.array(map(dcu.simple_image_featurization, training_data))
	return training_data, featurized_training_data, training_labels
开发者ID:j3nnahuang,项目名称:python,代码行数:7,代码来源:test_neuron.py

示例3: get_neuron_test_data

def get_neuron_test_data():
	test_data = samples.loadDataFile("digitdata/testimages", 1000, 28,28)
	test_labels = np.array(samples.loadLabelsFile("digitdata/testlabels", 1000))
	test_labels = test_labels == 3	

	featurized_test_data = np.array(map(dcu.simple_image_featurization, test_data))
	return test_data, featurized_test_data, test_labels
开发者ID:j3nnahuang,项目名称:python,代码行数:7,代码来源:test_neuron.py

示例4: testing

def testing(num):
    trainData = np.load("traindigitbasic.npy")
    trainLabels = samples.loadLabelsFile("data/digitdata/traininglabels", num)
    testData = np.load("testdigitbasic.npy")
    testLabels = samples.loadLabelsFile("data/digitdata/testlabels", 1000)
    validData = np.load("validationdigitbasic.npy")
    validLabels = samples.loadLabelsFile("data/digitdata/validationlabels", 1000)

    neural = NeuralNetworkClassifier(28 * 28, 50, 10, num, 3.5)
    neural.train(trainData[:, 0:num], trainLabels, 100)
    print "Test Data"
    guess = neural.classify(testData)
    samples.verify(neural, guess, testLabels)
    print "==================================="
    print "Validation Data"
    guess = neural.classify(validData)
    samples.verify(neural, guess, validLabels)
开发者ID:yzy14800,项目名称:520FinalProject,代码行数:17,代码来源:neural_d_basic.py

示例5: testing

def testing(num):
    trainData = samples.loadImagesFile("data/facedata/facedatatrain", num, 60, 70)
    trainLabels = samples.loadLabelsFile("data/facedata/facedatatrainlabels", num)
    testData = samples.loadImagesFile("data/facedata/facedatatest", 150, 60, 70)
    testLabels = samples.loadLabelsFile("data/facedata/facedatatestlabels", 151)
    validData = samples.loadImagesFile("data/facedata/facedatavalidation", 301, 60, 70)
    validLabels = samples.loadLabelsFile("data/facedata/facedatavalidationlabels", 301)

    perceptron=PerceptronClassifier(trainData, trainLabels,0)
    perceptron.train(trainData, trainLabels,10)
    print "==================================="
    print "Test Data"
    guess=perceptron.classify(testData)
    samples.verify(perceptron, guess, testLabels)
    print "==================================="
    print "Validation Data"
    guess=perceptron.classify(validData)
    samples.verify(perceptron,guess,validLabels)
开发者ID:yzy14800,项目名称:520FinalProject,代码行数:18,代码来源:perceptron_f_basic.py

示例6: testing

def testing(num):
    trainData = samples.loadImagesFile("data/digitdata/trainingimages", num, 28, 28)
    trainLabels = samples.loadLabelsFile("data/digitdata/traininglabels", num)
    testData = samples.loadImagesFile("data/digitdata/testimages", 1000, 28, 28)
    testLabels = samples.loadLabelsFile("data/digitdata/testlabels", 1000)
    validData = samples.loadImagesFile("data/digitdata/validationimages", 1000, 28, 28)
    validLabels = samples.loadLabelsFile("data/digitdata/validationlabels", 1000)

    nb = NaiveBayesClassifier(1,0)
    nb.train(trainData, trainLabels)
    print "==================================="
    print "Test Data"
    guess = nb.classify(testData)
    samples.verify(nb,guess,testLabels)
    print "==================================="
    print "Validation Data"
    guess=nb.classify(validData)
    samples.verify(nb,guess,validLabels)
开发者ID:yzy14800,项目名称:520FinalProject,代码行数:18,代码来源:nb_d_basic.py

示例7: testing

def testing(num):
    trainData = samples.loadImagesFile("data/facedata/facedatatrain", num, 60, 70)
    trainLabels = samples.loadLabelsFile("data/facedata/facedatatrainlabels", num)
    testData = samples.loadImagesFile("data/facedata/facedatatest", 150, 60, 70)
    testLabels = samples.loadLabelsFile("data/facedata/facedatatestlabels", 151)
    validData = samples.loadImagesFile("data/facedata/facedatavalidation", 301, 60, 70)
    validLabels = samples.loadLabelsFile("data/facedata/facedatavalidationlabels", 301)

    nb = NaiveBayesClassifier(1, 0)
    nb.train(trainData, trainLabels)
    print "==================================="
    print "Test Data"
    guess = nb.classify(testData)
    samples.verify(nb, guess, testLabels)
    print "==================================="
    print "Validation Data"
    guess = nb.classify(validData)
    samples.verify(nb, guess, validLabels)
开发者ID:yzy14800,项目名称:520FinalProject,代码行数:18,代码来源:nb_f_basic.py

示例8: testing

def testing(num):
    trainData = samples.loadImagesFile("data/digitdata/trainingimages", num, 28, 28)
    trainLabels = samples.loadLabelsFile("data/digitdata/traininglabels", num)
    testData = samples.loadImagesFile("data/digitdata/testimages", 1000, 28, 28)
    testLabels = samples.loadLabelsFile("data/digitdata/testlabels", 1000)
    validData = samples.loadImagesFile("data/digitdata/validationimages", 1000, 28, 28)
    validLabels = samples.loadLabelsFile("data/digitdata/validationlabels", 1000)

    perceptron=PerceptronClassifier(trainData, trainLabels,0)
    perceptron.train(trainData, trainLabels,10)
    print "==================================="
    print "Test Data"
    guess=perceptron.classify(testData)
    samples.verify(perceptron, guess, testLabels)
    print "==================================="
    print "Validation Data"
    guess=perceptron.classify(validData)
    samples.verify(perceptron,guess,validLabels)
开发者ID:yzy14800,项目名称:520FinalProject,代码行数:18,代码来源:perceptron_d_basic.py

示例9: testing

def testing(num):
    trainData = np.load("trainfacebasic.npy")
    trainLabels = samples.loadLabelsFile("data/facedata/facedatatrainlabels", num)
    testData = np.load("testfacebasic.npy")
    testLabels = samples.loadLabelsFile("data/facedata/facedatatestlabels", 151)
    validData = np.load("validationfacebasic.npy")
    validLabels = samples.loadLabelsFile("data/facedata/facedatavalidationlabels", 301)
    loop=True
    while loop:
        neural = NeuralNetworkClassifier(60 * 70, 500, 1, num, 0.03)
        neural.train(trainData[:,0:num], trainLabels, 100)
        print "Test Data"
        guess = neural.classify(testData)
        loop=samples.verify(neural, guess, testLabels)
        if loop:
            continue
        print "==================================="
        print "Validation Data"
        guess = neural.classify(validData)
        samples.verify(neural, guess, validLabels)
开发者ID:yzy14800,项目名称:520FinalProject,代码行数:20,代码来源:neural_f_basic.py

示例10: runClassifier

def runClassifier(args, options):
  classifier = args['classifier']
  printImage = args['printImage']
  # Load data  
  numTraining = options.training
  numTest = options.test
  if(options.data=="faces"):
    print "loading face data set"
    rawTrainingData = samples.loadDataFile("facedata/facedatatrain",FACE_DATUM_WIDTH,FACE_DATUM_HEIGHT)
    trainingLabels = samples.loadLabelsFile("facedata/facedatatrainlabels")
    rawValidationData = samples.loadDataFile("facedata/facedatavalidation",FACE_DATUM_WIDTH,FACE_DATUM_HEIGHT)
    validationLabels = samples.loadLabelsFile("facedata/facedatavalidationlabels")
    rawTestData = samples.loadDataFile("facedata/facedatatest", FACE_DATUM_WIDTH,FACE_DATUM_HEIGHT)
    testLabels = samples.loadLabelsFile("facedata/facedatatestlabels")
    rawTrainingData,trainingLabels=randomSample(rawTrainingData,trainingLabels,numTraining)
    rawTestData,testLabels=randomSample(rawTestData,testLabels,numTest)
  else:
    print "loading digit data set"
    rawTrainingData = samples.loadDataFile("digitdata/trainingimages",DIGIT_DATUM_WIDTH,DIGIT_DATUM_HEIGHT)
    trainingLabels = samples.loadLabelsFile("digitdata/traininglabels")
    rawValidationData = samples.loadDataFile("digitdata/validationimages",DIGIT_DATUM_WIDTH,DIGIT_DATUM_HEIGHT)
    validationLabels = samples.loadLabelsFile("digitdata/validationlabels")
    rawTestData = samples.loadDataFile("digitdata/testimages",DIGIT_DATUM_WIDTH,DIGIT_DATUM_HEIGHT)
    testLabels = samples.loadLabelsFile("digitdata/testlabels")
    rawTrainingData, trainingLabels = randomSample(rawTrainingData, trainingLabels, numTraining)
    rawTestData, testLabels = randomSample(rawTestData, testLabels, numTest)
  print "Extracting features..."
  if (options.classifier == "linear_svm"):
        if (options.data == "faces"):
            featureFunction = HogFeatureFaceImg
        else:
            featureFunction=HogFeatureImgDigit
        trainingData = map(featureFunction, rawTrainingData)
        trainingData=np.array(trainingData).transpose()
        validationData=map(featureFunction, rawValidationData)
        validationData = np.array(validationData).transpose()
        testData=map(featureFunction, rawTestData)
        testData = np.array(testData).transpose()
  else:
      if (options.data == "faces"):
          featureFunction = enhancedFeatureExtractorFace
      else:
          featureFunction = enhancedFeatureExtractorDigit
      trainingData = map(featureFunction, rawTrainingData)
      validationData = map(featureFunction, rawValidationData)
      testData = map(featureFunction, rawTestData)
  print "Training..."
  start = timeit.default_timer()
  classifier.train(trainingData, trainingLabels, validationData, validationLabels)
  stop = timeit.default_timer()
  print  stop - start, " s"
  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)
  correct = [guesses[i] == testLabels[i] for i in range(len(testLabels))].count(True)
  print str(correct), ("correct out of " + str(len(testLabels)) + " (%.1f%%).") % (100.0 * correct / len(testLabels))
  analysis(classifier, guesses, testLabels, testData, rawTestData, printImage)
开发者ID:sl1316,项目名称:Face-Digit-Classifier,代码行数:60,代码来源:dataClassifier.py

示例11: runClassifier

def runClassifier(args, options):

  featureFunction = args['featureFunction']
  classifier = args['classifier']
  printImage = args['printImage']
      
  # Load data  
  numTraining = options.training

  if(options.data=="faces"):
    rawTrainingData = samples.loadDataFile("facedata/facedatatrain", numTraining,FACE_DATUM_WIDTH,FACE_DATUM_HEIGHT)
    trainingLabels = samples.loadLabelsFile("facedata/facedatatrainlabels", numTraining)
    rawValidationData = samples.loadDataFile("facedata/facedatatrain", TEST_SET_SIZE,FACE_DATUM_WIDTH,FACE_DATUM_HEIGHT)
    validationLabels = samples.loadLabelsFile("facedata/facedatatrainlabels", TEST_SET_SIZE)
    rawTestData = samples.loadDataFile("facedata/facedatatest", TEST_SET_SIZE,FACE_DATUM_WIDTH,FACE_DATUM_HEIGHT)
    testLabels = samples.loadLabelsFile("facedata/facedatatestlabels", TEST_SET_SIZE)
  else:
    rawTrainingData = samples.loadDataFile("digitdata/trainingimages", numTraining,DIGIT_DATUM_WIDTH,DIGIT_DATUM_HEIGHT)
    trainingLabels = samples.loadLabelsFile("digitdata/traininglabels", numTraining)
    rawValidationData = samples.loadDataFile("digitdata/validationimages", TEST_SET_SIZE,DIGIT_DATUM_WIDTH,DIGIT_DATUM_HEIGHT)
    validationLabels = samples.loadLabelsFile("digitdata/validationlabels", TEST_SET_SIZE)
    rawTestData = samples.loadDataFile("digitdata/testimages", TEST_SET_SIZE,DIGIT_DATUM_WIDTH,DIGIT_DATUM_HEIGHT)
    testLabels = samples.loadLabelsFile("digitdata/testlabels", TEST_SET_SIZE)
    
  
  # Extract features
  print "Extracting features..."
  trainingData = map(featureFunction, rawTrainingData)
  validationData = map(featureFunction, rawValidationData)
  testData = map(featureFunction, rawTestData)
  
  # Conduct training and testing
  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)
  correct = [guesses[i] == testLabels[i] for i in range(len(testLabels))].count(True)
  print str(correct), ("correct out of " + str(len(testLabels)) + " (%.1f%%).") % (100.0 * correct / len(testLabels))
  analysis(classifier, guesses, testLabels, testData, rawTestData, printImage)
  
  # do odds ratio computation if specified at command line
  if((options.odds) & (options.classifier != "mostFrequent")):
    label1, label2 = options.label1, options.label2
    features_odds = classifier.findHighOddsFeatures(label1,label2)
    if(options.classifier == "naiveBayes" or options.classifier == "nb"):
      string3 = "=== Features with highest odd ratio of label %d over label %d ===" % (label1, label2)
    else:
      string3 = "=== Features for which weight(label %d)-weight(label %d) is biggest ===" % (label1, label2)    
      
    print string3
    printImage(features_odds)
开发者ID:lyeechong,项目名称:ai,代码行数:55,代码来源:dataClassifier.py

示例12: runClassifier

def runClassifier(args, options):

  featureFunction = args['featureFunction']
  classifier = args['classifier']
  printImage = args['printImage']
      
  # Load data  
  numTraining = options.training

  if(options.data=="faces"):
    rawTrainingData = samples.loadDataFile("facedata/facedatatrain", numTraining,FACE_DATUM_WIDTH,FACE_DATUM_HEIGHT)
    trainingLabels = samples.loadLabelsFile("facedata/facedatatrainlabels", numTraining)
    rawValidationData = samples.loadDataFile("facedata/facedatatrain", TEST_SET_SIZE,FACE_DATUM_WIDTH,FACE_DATUM_HEIGHT)
    validationLabels = samples.loadLabelsFile("facedata/facedatatrainlabels", TEST_SET_SIZE)
    rawTestData = samples.loadDataFile("facedata/facedatatest", TEST_SET_SIZE,FACE_DATUM_WIDTH,FACE_DATUM_HEIGHT)
    testLabels = samples.loadLabelsFile("facedata/facedatatestlabels", TEST_SET_SIZE)
  else:
    rawTrainingData = samples.loadDataFile("digitdata/trainingimages", numTraining,DIGIT_DATUM_WIDTH,DIGIT_DATUM_HEIGHT)
    trainingLabels = samples.loadLabelsFile("digitdata/traininglabels", numTraining)
    rawValidationData = samples.loadDataFile("digitdata/validationimages", TEST_SET_SIZE,DIGIT_DATUM_WIDTH,DIGIT_DATUM_HEIGHT)
    validationLabels = samples.loadLabelsFile("digitdata/validationlabels", TEST_SET_SIZE)
    rawTestData = samples.loadDataFile("digitdata/testimages", TEST_SET_SIZE,DIGIT_DATUM_WIDTH,DIGIT_DATUM_HEIGHT)
    testLabels = samples.loadLabelsFile("digitdata/testlabels", TEST_SET_SIZE)
    
  
  # Extract features
  print "Extracting features..."
  trainingData = map(featureFunction, rawTrainingData)
  validationData = map(featureFunction, rawValidationData)
  testData = map(featureFunction, rawTestData)
  
  # Conduct training and testing
  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)
  correct = [guesses[i] == testLabels[i] for i in range(len(testLabels))].count(True)
  print str(correct), ("correct out of " + str(len(testLabels)) + " (%.1f%%).") % (100.0 * correct / len(testLabels))
  analysis(classifier, guesses, testLabels, testData, rawTestData, printImage)
开发者ID:kyukyukyu,项目名称:kaist,代码行数:43,代码来源:dataClassifier.py

示例13: runClassifier

def runClassifier(args, options):

  featureFunction = args['featureFunction']
  classifier = args['classifier']
  printImage = args['printImage']
      
  # Load data  
  numTraining = options['train']

  if(options['data']=="faces"):
    rawTrainingData = samples.loadDataFile("facedata/facedatatrain", numTraining,FACE_DATUM_WIDTH,FACE_DATUM_HEIGHT)
    trainingLabels = samples.loadLabelsFile("facedata/facedatatrainlabels", numTraining)
    rawValidationData = samples.loadDataFile("facedata/facedatatrain", TEST_SET_SIZE,FACE_DATUM_WIDTH,FACE_DATUM_HEIGHT)
    validationLabels = samples.loadLabelsFile("facedata/facedatatrainlabels", TEST_SET_SIZE)
    rawTestData = samples.loadDataFile("facedata/facedatatest", TEST_SET_SIZE,FACE_DATUM_WIDTH,FACE_DATUM_HEIGHT)
    testLabels = samples.loadLabelsFile("facedata/facedatatestlabels", TEST_SET_SIZE)
  else:
    rawTrainingData = samples.loadDataFile("digitdata/trainingimages", numTraining,DIGIT_DATUM_WIDTH,DIGIT_DATUM_HEIGHT)
    trainingLabels = samples.loadLabelsFile("digitdata/traininglabels", numTraining)
    rawValidationData = samples.loadDataFile("digitdata/validationimages", TEST_SET_SIZE,DIGIT_DATUM_WIDTH,DIGIT_DATUM_HEIGHT)
    validationLabels = samples.loadLabelsFile("digitdata/validationlabels", TEST_SET_SIZE)
    rawTestData = samples.loadDataFile("digitdata/testimages", TEST_SET_SIZE,DIGIT_DATUM_WIDTH,DIGIT_DATUM_HEIGHT)
    testLabels = samples.loadLabelsFile("digitdata/testlabels", TEST_SET_SIZE)
    
  
  # Extract features
  print "Extracting features..."
  trainingData = map(featureFunction, rawTrainingData)
  validationData = map(featureFunction, rawValidationData)
  testData = map(featureFunction, rawTestData)
  
  # Conduct training and testing
  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)
  correct = [guesses[i] == testLabels[i] for i in range(len(testLabels))].count(True)
  print str(correct), ("correct out of " + str(len(testLabels)) + " (%.1f%%).") % (100.0 * correct / len(testLabels))
  util.pause()
  analysis(classifier, guesses, testLabels, testData, rawTestData, printImage)
  
  # do odds ratio computation if specified at command line
  if((options['odds']) & (options['classifier'] != "mostfrequent")):
    class1, class2 = options['class1'], options['class2']
    features_class1,features_class2,features_odds = classifier.findHighOddsFeatures(class1,class2)
    if(options['classifier'] == "naivebayes"):
      string1 = "=== Features with max P(F_i = 1 | class = %d) ===" % class1
      string2 = "=== Features with max P(F_i = 1 | class = %d) ===" % class2
      string3 = "=== Features with highest odd ratio of class %d over class %d ===" % (class1, class2)
    else:
      string1 = "=== Features with largest weight for class %d ===" % class1
      string2 = "=== Features with largest weight for class %d ===" % class2
      string3 = "=== Features with for which weight(class %d)-weight(class %d) is biggest ===" % (class1, class2)    
      
    print string1
    printImage(features_class1)
    print string2
    printImage(features_class2)
    print string3
    printImage(features_odds)
开发者ID:namidairo777,项目名称:cs188,代码行数:64,代码来源:dataClassifier.py

示例14: writeLabeledData

def writeLabeledData(prefix, labeled_data):
    datums, labels = zip(*labeled_data)

    with open(prefix + "images", 'w') as f:
        for datum in datums:
            f.write(str(datum) + "\n")
        f.close()

    with open(prefix + "labels", 'w') as f:
        for label in labels:
            f.write(str(label) + "\n")
        f.close()

rawTrainingData = samples.loadDataFile("digitdata/trainingimages", 5000,DIGIT_DATUM_WIDTH,DIGIT_DATUM_HEIGHT)
trainingLabels = samples.loadLabelsFile("digitdata/traininglabels", 5000)
rawValidationData = samples.loadDataFile("digitdata/validationimages", 1000,DIGIT_DATUM_WIDTH,DIGIT_DATUM_HEIGHT)
validationLabels = samples.loadLabelsFile("digitdata/validationlabels", 1000)
rawTestData = samples.loadDataFile("digitdata/testimages", 1000,DIGIT_DATUM_WIDTH,DIGIT_DATUM_HEIGHT)
testLabels = samples.loadLabelsFile("digitdata/testlabels", 1000)


all_data = rawTrainingData + rawValidationData + rawTestData
all_labels = trainingLabels + validationLabels + testLabels

labeled_data = zip(all_data, all_labels)

perm = np.random.permutation(len(labeled_data))

permuted_data = []
for i in perm:
开发者ID:MangoDreams,项目名称:cs151,代码行数:30,代码来源:permute_data.py

示例15: runClassifier

def runClassifier(args, options):

    featureFunction = args['featureFunction']
    classifier = args['classifier']
    printImage = args['printImage']

    # Load data    
    numTraining = options.training
    numTest = options.test

    if(options.data=="faces"):
        rawTrainingData = samples.loadDataFile("facedata/facedatatrain", numTraining,FACE_DATUM_WIDTH,FACE_DATUM_HEIGHT)
        trainingLabels = samples.loadLabelsFile("facedata/facedatatrainlabels", numTraining)
        rawValidationData = samples.loadDataFile("facedata/facedatatrain", numTest,FACE_DATUM_WIDTH,FACE_DATUM_HEIGHT)
        validationLabels = samples.loadLabelsFile("facedata/facedatatrainlabels", numTest)
        rawTestData = samples.loadDataFile("facedata/facedatatest", numTest,FACE_DATUM_WIDTH,FACE_DATUM_HEIGHT)
        testLabels = samples.loadLabelsFile("facedata/facedatatestlabels", numTest)
    else:
        rawTrainingData = samples.loadDataFile("digitdata/trainingimages", numTraining,DIGIT_DATUM_WIDTH,DIGIT_DATUM_HEIGHT)
        trainingLabels = samples.loadLabelsFile("digitdata/traininglabels", numTraining)
        rawValidationData = samples.loadDataFile("digitdata/validationimages", numTest,DIGIT_DATUM_WIDTH,DIGIT_DATUM_HEIGHT)
        validationLabels = samples.loadLabelsFile("digitdata/validationlabels", numTest)
        rawTestData = samples.loadDataFile("digitdata/testimages", numTest,DIGIT_DATUM_WIDTH,DIGIT_DATUM_HEIGHT)
        testLabels = samples.loadLabelsFile("digitdata/testlabels", numTest)


    # Extract features
    print "Extracting features..."
    trainingData = map(featureFunction, rawTrainingData)
    validationData = map(featureFunction, rawValidationData)
    testData = map(featureFunction, rawTestData)

    # Conduct training and testing
    print "Start training..."
    start = time.time()
    classifier.train(trainingData, trainingLabels, validationData, validationLabels)
    end = time.time() - start
    print "Traning time: " + str(end)
    print "Start validating..."
    guesses = classifier.classify(validationData)
    correct = [guesses[i] == validationLabels[i] for i in range(len(validationLabels))].count(True)
    print "Validation result: ", str(correct), ("correct out of " + str(len(validationLabels)) + " (%.1f%%).") % (100.0 * correct / len(validationLabels))
    print "Start testing..."
    guesses = classifier.classify(testData)
    correct = [guesses[i] == testLabels[i] for i in range(len(testLabels))].count(True)
    print "Testing result: ", str(correct), ("correct out of " + str(len(testLabels)) + " (%.1f%%).") % (100.0 * correct / len(testLabels))
    #analysis(classifier, guesses, testLabels, testData, rawTestData, printImage)

    # do odds ratio computation if specified at command line
    if((options.odds) & (options.classifier == NB) ):
        label1, label2 = options.label1, options.label2
        features_odds = classifier.findHighOddsFeatures(label1,label2)
        if(options.classifier == NB):
            string3 = "=== Features with highest odd ratio of label %d over label %d ===" % (label1, label2)
        else:
            string3 = "=== Features for which weight(label %d)-weight(label %d) is biggest ===" % (label1, label2)        

        print string3
        printImage(features_odds)

    if((options.weights) & (options.classifier == PT)):
        for l in classifier.legalLabels:
            features_weights = classifier.findHighWeightFeatures(l)
            print ("=== Features with high weight for label %d ==="%l)
            printImage(features_weights)
开发者ID:orcax,项目名称:image-classify,代码行数:65,代码来源:dataClassifier.py


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