Beispiel #1
0
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,
                                        epochs=10)

    # Train the classifiers
    print("=========================")
    print("Training..")
    myStupidClassifier.train()
    myPerceptronClassifier.train()

    # Do the recognizer
    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)
Beispiel #2
0
def main():
    data = MNISTSeven("../data/mnist_seven.csv", 3000, 1000, 1000, oneHot=True)
    myStupidClassifier = StupidRecognizer(data.trainingSet, data.validationSet,
                                          data.testSet)
    myPerceptronClassifier = Perceptron(data.trainingSet,
                                        data.validationSet,
                                        data.testSet,
                                        learningRate=0.005,
                                        epochs=30)

    myLRClassifier = LogisticRegression(data.trainingSet,
                                        data.validationSet,
                                        data.testSet,
                                        learningRate=0.005,
                                        epochs=30)

    # 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..")

    print("\nLogistic Regression has been training..")
    myLRClassifier.train()
    print("Done..")

    # Do the recognizer
    # Explicitly specify the test set to be evaluated
    stupidPred = myStupidClassifier.evaluate()
    perceptronPred = myPerceptronClassifier.evaluate()
    lrPred = myLRClassifier.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, perceptronPred)
    evaluator.printAccuracy(data.testSet, lrPred)
Beispiel #3
0
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=0.005,
                                        epochs=30)
    myLRClassifier = LogisticRegression(data.trainingSet,
                                        data.validationSet,
                                        data.testSet,
                                        learningRate=0.005,
                                        epochs=30)

    # 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..")

    print("\nLogistic Regression has been training..")
    myLRClassifier.train()
    print("Done..")

    # Do the recognizer
    # Explicitly specify the test set to be evaluated
    stupidPred = myStupidClassifier.evaluate()
    perceptronPred = myPerceptronClassifier.evaluate()
    lrPred = myLRClassifier.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, perceptronPred)    
    evaluator.printAccuracy(data.testSet, lrPred)
Beispiel #4
0
def main():
    data = MNISTSeven("../data/mnist_seven.csv", 3000, 1000, 1000)
    myStupidClassifier = StupidRecognizer(data.trainingSet, data.validationSet,
                                          data.testSet)
    # Uncomment this to make your Perceptron evaluated
    myPerceptronClassifier = Perceptron(
        data.trainingSet,
        data.validationSet,
        data.testSet,
        learningRate=1.0,  #0.005,
        epochs=1  #30
    )

    # 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()
    # Uncomment this to make your Perceptron evaluated
    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)
    # Uncomment this to make your Perceptron evaluated
    evaluator.printAccuracy(data.testSet, perceptronPred)

    evaluator.printConfusionMatrix(data.testSet, perceptronPred)
    evaluator.printClassificationResult(data.testSet, perceptronPred,
                                        ['class 0', 'class 1'])  #target_names)
Beispiel #5
0
def main():
    data = MNISTSeven("../data/mnist_seven.csv", 3000, 1000, 1000,
                                                    oneHot=False)

    data.trainingSet.input = np.insert(data.trainingSet.input, 0, 1,
                                        axis=1)
    data.validationSet.input = np.insert(data.validationSet.input, 0, 1,
                                          axis=1)
    data.testSet.input = np.insert(data.testSet.input, 0, 1, axis=1)

    myStupidClassifier = StupidRecognizer(data.trainingSet,
                                          data.validationSet,
                                          data.testSet)
    
    # myPerceptronClassifier = Perceptron(data.trainingSet,
    #                                     data.validationSet,
    #                                     data.testSet,
    #                                     learningRate=0.005,
    #                                     epochs=30)
                                        
    # myLRClassifier = LogisticRegression(data.trainingSet,
    #                                     data.validationSet,
    #                                     data.testSet,
    #                                     learningRate=0.005,
    #                                     epochs=30)

    MLPClassifier = MultilayerPerceptron(data.trainingSet, 
                        data.validationSet, 
                        data.testSet,
                        netStruct = [800, 100, 10], 
                        actFunc = ['relu', 'relu', 'softmax'], 
                        dropout = True,
                        loss = 'crossentropy',
                        learningRate = 0.001,
                        epochs = 300)

    
    # Report the result #
    print("=========================")
    evaluator = Evaluator()                                        

    # 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..")
    
    # print("\nLogistic Regression has been training..")
    # myLRClassifier.train()
    # print("Done..")

    print("\nMLP has been training..")
    MLPClassifier.train()
    print("Done..")

    # Do the recognizer
    # Explicitly specify the test set to be evaluated
    # stupidPred = myStupidClassifier.evaluate()
    # perceptronPred = myPerceptronClassifier.evaluate()
    # lrPred = myLRClassifier.evaluate()
    mlpPred = MLPClassifier.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("\nResult of the MLP recognizer:")
    # evaluator.printComparison(data.testSet, lrPred)    
    evaluator.printAccuracy(data.testSet, mlpPred)

    # Draw
    # plot = PerformancePlot("MLP validation")
    # plot.draw_performance_epoch(MLPClassifier.performances,
    #                             MLPClassifier.epochs)

    plt.plot(range(MLPClassifier.epochs), MLPClassifier.performances, 'r--')
    plt.show()
Beispiel #6
0
def main():
    data = MNISTSeven("../data/mnist_seven.csv",
                      3000,
                      1000,
                      1000,
                      oneHot=False)
    myStupidClassifier = StupidRecognizer(data.trainingSet, data.validationSet,
                                          data.testSet)

    #myPerceptronClassifier = Perceptron(data.trainingSet,
    #data.validationSet,
    #data.testSet,
    #learningRate=0.005,
    #epochs=30)

    #myLRClassifier = LogisticRegression(data.trainingSet,
    #data.validationSet,
    #data.testSet,
    #learningRate=0.005,
    #epochs=30)

    mlp = MultilayerPerceptron(data.trainingSet,
                               data.validationSet,
                               data.testSet,
                               layers=None,
                               inputWeights=None,
                               outputTask='classification',
                               outputActivation='softmax',
                               loss='cee',
                               learningRate=0.01,
                               epochs=50)

    # Report the result #
    print("=========================")
    evaluator = Evaluator()

    # 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..")

    print("\nLogistic Regression has been training..")
    #myLRClassifier.train()
    print("Done..")

    print("\nmlp has been training..")
    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 = MultilayerPerceptron.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:")
    evaluator.printAccuracy(data.testSet, mlppred)

    # Draw
    #plot = PerformancePlot("Logistic Regression validation")
    #plot.draw_performance_epoch(myLRClassifier.performances,
    #myLRClassifier.epochs)
    ####可能有问题
    plot = PerformancePlot("mlp validation")
    plot.draw_performance_epoch(mlp.performances, mlp.epochs)
Beispiel #7
0
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=0.005,
                                        epochs=30)
    myLRClassifier = LogisticRegression(data.trainingSet,
                                        data.validationSet,
                                        data.testSet,
                                        learningRate=0.005,
                                        epochs=30)
    MlpClassifier = MultilayerPerceptron(data.trainingSet,
                                                data.validationSet,
                                                data.testSet,
                                                learningRate=0.1,
                                                epochs = 30)

    # 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..")

    # print("\nLogistic Regression has been training..")
    # myLRClassifier.train()
    # print("Done..")

    print("\nStarting Backpropagation MLP training...")
    MlpClassifier.train()
    print("Done..")

    # Do the recognizer
    # Explicitly specify the test set to be evaluated
    stupidPred = myStupidClassifier.evaluate()
    # perceptronPred = myPerceptronClassifier.evaluate()
    # lrPred = myLRClassifier.evaluate()
    mlpPred = MlpClassifier.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, perceptronPred)    
    # evaluator.printAccuracy(data.testSet, lrPred)

    print("\nResult of the MLP recognizer:")
    # evaluator.printComparison(data.testSet, perceptronPred)
    evaluator.printAccuracy(data.testSet, mlpPred)

    # eval.printConfusionMatrix(data.testSet, pred)
    # eval.printClassificationResult(data.testSet, pred, target_names)

    print("=========================")
Beispiel #8
0
def main():
    data = MNISTSeven("../data/mnist_seven.csv", 3000, 1000, 1000)
    myStupidClassifier = StupidRecognizer(data.trainingSet, data.validationSet,
                                          data.testSet)

    # parameters
    learnRate = 0.005
    maxEpochs = 20
    #epochNumber = 30

    xEpochs = []
    yAccuracyPerceptron = []
    yAccuracyLogistic = []
    # loop for gathering data for graph plotting
    for epochNumber in xrange(1, maxEpochs + 1):

        myPerceptronClassifier = Perceptron(
            data.trainingSet,
            data.validationSet,
            data.testSet,
            learningRate=learnRate,  #0.005,
            epochs=epochNumber)
        # Uncomment this to run Logistic Neuron Layer
        myLRClassifier = LogisticRegression(
            data.trainingSet,
            data.validationSet,
            data.testSet,
            learningRate=learnRate,  #0.005,
            epochs=epochNumber  #30
        )

        # 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..")

        print("\nLogistic Regression has been training..")
        myLRClassifier.train()
        print("Done..")

        # Do the recognizer
        # Explicitly specify the test set to be evaluated
        stupidPred = myStupidClassifier.evaluate()
        perceptronPred = myPerceptronClassifier.evaluate()
        lrPred = myLRClassifier.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)

        # accumulate plotting data
        xEpochs.append(epochNumber)
        yAccuracyPerceptron.append(
            accuracy_score(data.testSet.label, perceptronPred) * 100)
        yAccuracyLogistic.append(
            accuracy_score(data.testSet.label, lrPred) * 100)

        # === end of for loop ===

    # plot the graph
    plt.plot(xEpochs, yAccuracyPerceptron, marker='o', label='Perceptron')
    plt.plot(xEpochs,
             yAccuracyLogistic,
             marker='o',
             color='r',
             label='Logistic Neuron')
    plt.xlabel('Number of epochs')
    plt.ylabel('Accuracy [%]')
    plt.title(
        'Performance on different epochs\n(using: testSet | learningRate: ' +
        str(learnRate) + ')')
    #plt.legend()
    plt.legend(loc=4)
    #plt.legend(bbox_to_anchor=(0., 1.02, 1., .102), loc=3, ncol=2, mode="expand", borderaxespad=0.)
    #plt.legend(bbox_to_anchor=(1.05, 1), loc=2, borderaxespad=0.)
    plt.show()
Beispiel #9
0
def classify_one():
    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.20,
                                        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()

    # Logistic Regression
    myMLPClassifier = MultilayerPerceptron(data.training_set,
                                           data.validation_set,
                                           data.test_set,
                                           learning_rate=0.30,
                                           epochs=50)

    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("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.testSet, perceptronPred)
    evaluator.printAccuracy(data.test_set, mlpPred)


    # Draw
    plot = PerformancePlot("Logistic Regression")
    plot.draw_performance_epoch(myLRClassifier.performances,
                                myLRClassifier.epochs)
Beispiel #10
0
def main():
    data = MNISTSeven("data/mnist_seven.csv", 3000, 1000, 1000, oneHot=True)
    myStupidClassifier = StupidRecognizer(data.trainingSet, data.validationSet,
                                          data.testSet)

    myPerceptronClassifier = Perceptron(data.trainingSet,
                                        data.validationSet,
                                        data.testSet,
                                        learningRate=0.005,
                                        epochs=30)

    myLRClassifier = LogisticRegression(data.trainingSet,
                                        data.validationSet,
                                        data.testSet,
                                        learningRate=0.005,
                                        epochs=30)

    # Report the result #
    print("=========================")
    evaluator = Evaluator()

    # 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..")

    # print("\nLogistic Regression has been training..")
    # myLRClassifier.train()
    # print("Done..")

    myMLP = MultilayerPerceptron(data.trainingSet,
                                 data.validationSet,
                                 data.testSet,
                                 learningRate=0.01,
                                 epochs=30,
                                 loss="ce",
                                 outputActivation="softmax",
                                 weight_decay=0.1)

    print("\nMLP has been training..")
    myMLP.train()
    print("Done..")

    # Do the recognizer
    # Explicitly specify the test set to be evaluated
    # stupidPred = myStupidClassifier.evaluate()
    # perceptronPred = myPerceptronClassifier.evaluate()
    # lrPred = myLRClassifier.evaluate()
    mlpPred = myMLP.evaluate(data.validationSet)

    # # 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("\nResult of the Multilayer Perceptron recognizer:")
    #evaluator.printComparison(data.testSet, lrPred)
    # evaluator.printAccuracy(data.testSet, mlpPred)

    plot = PerformancePlot("MLP validation")
    plot.draw_performance_epoch(myMLP.performances, myMLP.epochs)
Beispiel #11
0
def classify_one():
    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.20,
                                        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()

    # Logistic Regression
    myMLPClassifier = MultilayerPerceptron(data.training_set,
                                           data.validation_set,
                                           data.test_set,
                                           learning_rate=0.30,
                                           epochs=50)

    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("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.testSet, perceptronPred)
    evaluator.printAccuracy(data.test_set, mlpPred)

    # Draw
    plot = PerformancePlot("Logistic Regression")
    plot.draw_performance_epoch(myLRClassifier.performances,
                                myLRClassifier.epochs)
Beispiel #12
0
def main():
    data = MNISTSeven("../data/mnist_seven.csv", 3000, 1000, 1000)
    myStupidClassifier = StupidRecognizer(data.trainingSet, data.validationSet,
                                          data.testSet)
    mylogisticClassifier = LogisticRegression(data.trainingSet,
                                              data.validationSet,
                                              data.testSet,
                                              learningRate=0.005,
                                              epochs=30)
    # Train the classifiers
    print("=========================")
    print("Training..")

    print("\nStupid Classifier has been training..")
    myStupidClassifier.train()
    print("Done..")

    print("\nLogsticregression has been training..")
    mylogisticClassifier.train()
    print("Done..")

    # Do the recognizer
    # Explicitly specify the test set to be evaluated
    stupidPred = myStupidClassifier.evaluate()
    perceptronPred = mylogisticClassifier.evaluate()

    # Report the result
    print("=========================")
    evaluator = Evaluator()

    print("Result of the stupid recognizer:")
    # evaluator.printComparison(data.testSet, stupidPred)
    evaluator.printAccuracy(data.testSet, stupidPred)

    print("\n Result of the Logsticregression recognizer:")
    # evaluator.printComparison(data.testSet, perceptronPred)
    evaluator.printAccuracy(data.testSet, perceptronPred)
    for i in range(2):
        for j in range(2):
            learningRate = (i + 1) * 0.002
            epochs = (j + 1) * 20

            mylogisticClassifier = LogisticRegression(
                data.trainingSet,
                data.validationSet,
                data.testSet,
                learningRate=learningRate,
                epochs=epochs)

            # Train the classifiers
            print("=========================")
            print("learning rate :" + str(learningRate))
            print("epoch :" + str(epochs))
            print("Training..")

            print("\nLogsticregression has been training..")
            mylogisticClassifier.train()
            print("Done..")

            # Do the recognizer
            # Explicitly specify the test set to be evaluated
            perceptronPred = mylogisticClassifier.evaluate()

            # Report the result
            print("=========================")
            evaluator = Evaluator()

            print("\n Result of the Logsticregression recognizer:")
            # evaluator.printComparison(data.testSet, perceptronPred)
            evaluator.printAccuracy(data.testSet, perceptronPred)