test_character_list = chf.load_characters_kaggle_format(character_file_directory +\ character_test_file_name, 'train', (0,100)) for i in range(train_character_list.shape[0]): char = train_character_list[i] char.calculate_char_features() for i in range(test_character_list.shape[0]): if i % 1000 == 0: print("calculating features for " + str(i) + "th test event...") test_character_list[i].calculate_char_features() print('begin softmax regression...') Lambda = 0.05 sr.softmax_regression(train_character_list, test_character_list, Lambda) correct_classifications = np.zeros(ch.character.total_classifications) total_instances = np.zeros(ch.character.total_classifications) for i in range(test_character_list.shape[0]): char = test_character_list[i] if char._predicted_classification == char._classification: correct_classifications[int( char._classification)] = correct_classifications[int( char._classification)] + 1 total_instances[int( char._classification)] = total_instances[int(char._classification)] + 1
for i in range(train_character_list.shape[0]): char = train_character_list[i] char.calculate_char_features() for i in range(test_character_list.shape[0]): if i%1000 == 0: print("calculating features for " + str(i) + "th test event...") test_character_list[i].calculate_char_features() print('begin softmax regression...') Lambda = 0.05 sr.softmax_regression(train_character_list, test_character_list, Lambda) correct_classifications = np.zeros(ch.character.total_classifications) total_instances = np.zeros(ch.character.total_classifications) for i in range(test_character_list.shape[0]): char = test_character_list[i] if char._predicted_classification == char._classification: correct_classifications[int(char._classification)] = correct_classifications[int(char._classification)] + 1 total_instances[int(char._classification)] = total_instances[int(char._classification)] + 1 for i in range(0, ch.character.total_classifications): print('i = ' + str(i) + ': ' + str(correct_classifications[i]) + "/" + str(total_instances[i]))
num_correct += 1 return float(num_correct) / groundTruth.shape[0] # percent total accuracy if __name__ == "__main__": args = parser.parse_args() trainMatrix = datapath + args.trainMatrix trainLabels = datapath + args.trainLabels testMatrix = datapath + args.testMatrix testLabels = datapath + args.testLabels num_classes = args.num_classes # load training data X = np.load(trainMatrix) y = np.load(trainLabels) # train softmax regression Theta = softmax.softmax_regression( X, y, num_classes, args.reg_param, args.max_iters, args.alpha, args.converg_tol, args.verbose ) # load test data testMatrix = np.load(testMatrix) testMatrix = np.append(np.ones((testMatrix.shape[0], 1)), testMatrix, 1) # append column of 1s for intercept term testLabels = np.load(testLabels) predictions = make_predictions(Theta, testMatrix) print "Accuracy is ", evaluate_predictions(predictions, testLabels, num_classes)
num_correct += 1 return float(num_correct) / groundTruth.shape[0] #percent total accuracy if __name__ == "__main__": args = parser.parse_args() trainMatrix = datapath + args.trainMatrix trainLabels = datapath + args.trainLabels testMatrix = datapath + args.testMatrix testLabels = datapath + args.testLabels num_classes = args.num_classes #load training data X = np.load(trainMatrix) y = np.load(trainLabels) #train softmax regression Theta = softmax.softmax_regression (X, y, num_classes, args.reg_param, args.max_iters, \ args.alpha, args.converg_tol, args.verbose) #load test data testMatrix = np.load(testMatrix) testMatrix = np.append(np.ones((testMatrix.shape[0], 1)), testMatrix, 1) #append column of 1s for intercept term testLabels = np.load(testLabels) predictions = make_predictions(Theta, testMatrix) print "Accuracy is ", evaluate_predictions(predictions, testLabels, num_classes)
def main(): input = input_pipeline() print("ready input pipeline") net = softmax_regression() _solver = solver(net, input, './log') _solver.train_and_test()