本文整理汇总了Python中samples.loadLabelsFile函数的典型用法代码示例。如果您正苦于以下问题:Python loadLabelsFile函数的具体用法?Python loadLabelsFile怎么用?Python loadLabelsFile使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了loadLabelsFile函数的18个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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
示例16: runClassifier
def runClassifier(args, options):
#print 'args: ', args
#print 'options', 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..."
#print '#######type of rawTrainingData is', rawTrainingData.__class__ # list of Datum
#print '#######type of rawTrainingData[0] is', rawTrainingData[0].__class__ # Datum
trainingData = map(featureFunction, rawTrainingData)
#print '#######type of trainingData is', trainingData.__class__ # list of Counter
#print '#######type of trainingData[0] is', trainingData[0].__class__ # Counter
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 == "naiveBayes" or (options.classifier == "nb")) ):
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)
if((options.weights) & (options.classifier == "perceptron")):
for l in classifier.legalLabels:
features_weights = classifier.findHighWeightFeatures(l)
print ("=== Features with high weight for label %d ==="%l)
printImage(features_weights)
开发者ID:minus-plus,项目名称:a_project,代码行数:67,代码来源:dataClassifier_v1.py
示例17: 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=="pacman"):
agentToClone = args.get('agentToClone', None)
trainingData, validationData, testData = MAP_AGENT_TO_PATH_OF_SAVED_GAMES.get(agentToClone, (None, None, None))
trainingData = trainingData or args.get('trainingData', False) or MAP_AGENT_TO_PATH_OF_SAVED_GAMES['ContestAgent'][0]
validationData = validationData or args.get('validationData', False) or MAP_AGENT_TO_PATH_OF_SAVED_GAMES['ContestAgent'][1]
testData = testData or MAP_AGENT_TO_PATH_OF_SAVED_GAMES['ContestAgent'][2]
rawTrainingData, trainingLabels = samples.loadPacmanData(trainingData, numTraining)
rawValidationData, validationLabels = samples.loadPacmanData(validationData, numTest)
rawTestData, testLabels = samples.loadPacmanData(testData, 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 "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 == "naiveBayes" or (options.classifier == "nb")) ):
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)
if((options.weights) & (options.classifier == "perceptron")):
for l in classifier.legalLabels:
features_weights = classifier.findHighWeightFeatures(l)
print ("=== Features with high weight for label %d ==="%l)
printImage(features_weights)
开发者ID:SoloistRoy,项目名称:CS188-Project5-Classifier,代码行数:63,代码来源:dataClassifier.py
示例18: runClassifier
def runClassifier(args, options):
classifier = args['classifier']
classifierArgs = args['classifierArgs']
# import statements here because sys.path may be altered to point
# to student code
import featureExtractors
import featureExtractorsBasic
import mostFrequent
import decisionTree
import decisionStump
import naiveBayes
import perceptron
import mira
import diffDecisionTree
# Load data
numTraining = options.training
numTest = options.test
if(options.data.endswith('.arff')):
data, labels = samples.loadARFFDataFile("data/arffdata/"+options.data, numTraining+numTest)
rawTrainingData, rawTestData = data[:numTraining], data[numTraining:numTraining+numTest]
trainingLabels, testLabels = labels[:numTraining], labels[numTraining:numTraining+numTest]
legalLabels = set(trainingLabels)
elif(options.data=="spam"):
rawTrainingData = samples.loadSpamData("data/spamdata/trainingdata", numTraining)
trainingLabels = samples.loadLabelsFile("data/spamdata/traininglabels.txt", numTraining)
rawTestData = samples.loadSpamData("data/spamdata/testdata", numTest)
testLabels = samples.loadLabelsFile("data/spamdata/testlabels.txt", numTest)
legalLabels = ['1', '0']
elif(options.data=="digits"):
DIGIT_DATUM_WIDTH=28
DIGIT_DATUM_HEIGHT=28
rawTrainingData = samples.loadDigitsDataFile("data/digitdata/trainingimages", numTraining,DIGIT_DATUM_WIDTH,DIGIT_DATUM_HEIGHT)
trainingLabels = samples.loadLabelsFile("data/digitdata/traininglabels", numTraining)
rawTestData = samples.loadDigitsDataFile("data/digitdata/testimages", numTest,DIGIT_DATUM_WIDTH,DIGIT_DATUM_HEIGHT)
testLabels = samples.loadLabelsFile("data/digitdata/testlabels", numTest)
legalLabels = set(trainingLabels)
else:
print "Unknown dataset", options.data
print USAGE_STRING
sys.exit(2)
# Load classifier
if(options.classifier == "mostFrequent"):
classifier = mostFrequent.MostFrequentClassifier(legalLabels, **classifierArgs)
elif(options.classifier == "dt" or options.classifier == "decisionTree"):
classifier = decisionTree.DecisionTreeClassifer(legalLabels, **classifierArgs)
elif(options.classifier == "diffTree"):
classifier = diffDecisionTree.DiffDecisionTreeClassifer(legalLabels, **classifierArgs)
elif(options.classifier == "stump"):
classifier = decisionStump.DecisionStumpClassifer(legalLabels, **classifierArgs)
elif(options.classifier == "naiveBayes" or options.classifier == "nb"):
classifier = naiveBayes.NaiveBayesClassifier(legalLabels, **classifierArgs)
elif(options.classifier == "perceptron"):
classifier = perceptron.PerceptronClassifier(legalLabels,**classifierArgs)
elif(options.classifier == "mira"):
classifier = mira.MiraClassifier(legalLabels,**classifierArgs)
# Load feature extractors
if (options.data.endswith('.arff')):
if options.classifier in ['nb', 'perceptron', 'mira']:
make_binary = True
else:
make_binary = False
extractor = featureExtractorsBasic.IdentityFeatureExtractor(make_binary)
elif (options.data=='spam'):
if options.features:
extractor = featureExtractors.EnhancedEmailFeatureExtractor()
else:
extractor = featureExtractors.EmailFeatureExtractor()
else:
assert options.data=="digits"
if options.features:
extractor = featureExtractors.EnhancedDigitFeatureExtractor()
else:
extractor = featureExtractors.DigitFeatureExtractor()
if options.training <= 0:
print "Training set size should be a positive integer (you provided: %d)" % options.training
print USAGE_STRING
sys.exit(2)
featureFunction = extractor.extractFeatures
# Preprocess data
print "Preprocessing data..."
map(extractor.preProcess, rawTrainingData)
extractor.finalizeFeatures()
assert len(rawTrainingData) == len(trainingLabels)
# Extract features
print "Extracting features..."
trainingData = map(featur
|
请发表评论