def main(): data = MNISTSeven("../data/mnist_seven.csv", 3000, 1000, 1000, oneHot=False) myMLPClassifier = MultilayerPerceptron(data.trainingSet, data.validationSet, data.testSet, loss='ce', layers=[128, 150], learningRate=0.005, epochs=10) # Report the result # # Train the classifiers print("=========================") print("Training..") print("\nMultilayer Perceptron has been training..") myMLPClassifier.train() print("Done..") # Do the recognizer # Explicitly specify the test set to be evaluated mlpPred = myMLPClassifier.evaluate() # Report the result print("=========================") evaluator = Evaluator() print("\nResult of the Multi Layer Perceptron recognizer:") evaluator.printComparison(data.testSet, mlpPred) evaluator.printAccuracy(data.testSet, mlpPred) # Draw plot = PerformancePlot("Multi Layer Perceptron validation") plot.draw_performance_epoch(myMLPClassifier.performances, myMLPClassifier.epochs)
def main(): data = MNISTSeven("../data/mnist_seven.csv", 3000, 1000, 1000) # myStupidClassifier = StupidRecognizer(data.trainingSet, # data.validationSet, # data.testSet) myPerceptronClassifier = Perceptron(data.trainingSet, data.validationSet, data.testSet, learningRate=1e-2, epochs=1000) # Train the classifiers print("=========================") print("Training..") print("\nStupid Classifier has been training..") # myStupidClassifier.train() print("Done..") print("\nPerceptron has been training..") myPerceptronClassifier.train() print("Done..") # Do the recognizer # Explicitly specify the test set to be evaluated # stupidPred = myStupidClassifier.evaluate() perceptronPred = myPerceptronClassifier.evaluate() # Report the result print("=========================") evaluator = Evaluator() print("Result of the stupid recognizer:") # evaluator.printComparison(data.testSet, stupidPred) # evaluator.printAccuracy(data.testSet, stupidPred) print("\nResult of the Perceptron recognizer:") evaluator.printComparison(data.testSet, perceptronPred) evaluator.printAccuracy(data.testSet, perceptronPred)
def main(): data = MNISTSeven("../data/mnist_seven.csv", 3000, 1000, 1000, oneHot=False) # myLRClassifier = LogisticRegression(data.trainingSet, # data.validationSet, # data.testSet, # learningRate=0.005, # epochs=30) hidden_layers = [ LogisticLayer(128, 32, isClassifierLayer=True) for layer in range(1) ] mlp = MultilayerPerceptron(data.trainingSet, data.validationSet, data.testSet, hidden_layers, learningRate=0.005, epochs=30) # Train the classifiers #print("=========================") print("Training...") # print("\nLogistic Regression has been training..") # myLRClassifier.train() # print("Done..") print("Training MLP...") mlp.train() print("Done.") # Do the recognizer # Explicitly specify the test set to be evaluated # stupidPred = myStupidClassifier.evaluate() # perceptronPred = myPerceptronClassifier.evaluate() # lrPred = myLRClassifier.evaluate() mlpPred = mlp.evaluate() # Report the result print("=========================") evaluator = Evaluator() # print("Result of the stupid recognizer:") # # #evaluator.printComparison(data.testSet, stupidPred) # # evaluator.printAccuracy(data.testSet, stupidPred) # # # # print("\nResult of the Perceptron recognizer:") # # #evaluator.printComparison(data.testSet, perceptronPred) # # evaluator.printAccuracy(data.testSet, perceptronPred) # # # # print("\nResult of the Logistic Regression recognizer:") # # #evaluator.printComparison(data.testSet, lrPred) # # evaluator.printAccuracy(data.testSet, lrPred) print("Result of the MLP recognizer:") evaluator.printComparison(data.testSet, mlpPred) evaluator.printAccuracy(data.testSet, mlpPred) # Draw plot = PerformancePlot("Logistic Regression validation") # plot.draw_performance_epoch(myLRClassifier.performances, # myLRClassifier.epochs) plot.draw_performance_epoch(mlp.performances, mlp.epochs)
def main(): # data = MNISTSeven("../data/mnist_seven.csv", 3000, 1000, 1000, # one_hot=True, target_digit='7') # NOTE: # Comment out the MNISTSeven instantiation above and # uncomment the following to work with full MNIST task data = MNISTSeven("../data/mnist_seven.csv", 3000, 1000, 1000, one_hot=False) # NOTE: # Other 1-digit classifiers do not make sense now for comparison purpose # So you should comment them out, let alone the MLP training and evaluation # Train the classifiers # print("=========================") print("Training..") # Stupid Classifier # myStupidClassifier = StupidRecognizer(data.training_set, # data.validation_set, # data.test_set) # print("\nStupid Classifier has been training..") # myStupidClassifier.train() # print("Done..") # Do the recognizer # Explicitly specify the test set to be evaluated # stupidPred = myStupidClassifier.evaluate() # Perceptron # myPerceptronClassifier = Perceptron(data.training_set, # data.validation_set, # data.test_set, # learning_rate=0.005, # epochs=10) # # print("\nPerceptron has been training..") # myPerceptronClassifier.train() # print("Done..") # Do the recognizer # Explicitly specify the test set to be evaluated # perceptronPred = myPerceptronClassifier.evaluate() # Logistic Regression # myLRClassifier = LogisticRegression(data.training_set, # data.validation_set, # data.test_set, # learning_rate=0.005, # epochs=30) # # print("\nLogistic Regression has been training..") # myLRClassifier.train() # print("Done..") # Do the recognizer # Explicitly specify the test set to be evaluated # lrPred = myLRClassifier.evaluate() # Multi layer perceptron layers = [LogisticLayer(data.training_set.input.shape[1], 30, None, 'sigmoid', False), LogisticLayer(30, 10, None, 'softmax', True)] myMLPClassifier = MultilayerPerceptron(data.training_set, data.validation_set, data.test_set, layers=layers, learning_rate=0.005, epochs=30) print("\nLogistic Regression has been training..") myMLPClassifier.train() print("Done..") # Do the recognizer # Explicitly specify the test set to be evaluated mlpPred = myMLPClassifier.evaluate() # Report the result # print("=========================") evaluator = Evaluator() # print("Result of the stupid recognizer:") # evaluator.printComparison(data.testSet, stupidPred) # evaluator.printAccuracy(data.test_set, stupidPred) # print("\nResult of the Perceptron recognizer (on test set):") # evaluator.printComparison(data.testSet, perceptronPred) # evaluator.printAccuracy(data.test_set, perceptronPred) # print("\nResult of the Logistic Regression recognizer (on test set):") # evaluator.printComparison(data.testSet, perceptronPred) # evaluator.printAccuracy(data.test_set, lrPred) print("\nResult of the Multi-layer Perceptron recognizer (on test set):") evaluator.printComparison(data.test_set, mlpPred) evaluator.printAccuracy(data.test_set, mlpPred)