Ejemplo n.º 1
0
def main():
    """
    Learn a Naive Bayes classifier on the digit dataset, evaluate its
    performance on training and test sets, then visualize the mean and variance
    for each class.
    """

    train_inputs, train_targets = load_train()
    valid_inputs, valid_targets = load_valid()
    test_inputs, test_targets = load_test()

    # add your code here (it should be less than 10 lines)
    self = NaiveBayesClassifier()
    self.train(train_inputs, train_targets)
    test_prediction = self.predict(test_inputs)
    valid_accuracy = self.compute_accuracy(valid_inputs, valid_targets)
    test_accuracy = self.compute_accuracy(test_inputs, test_targets)
    print "valid accuracy: ", valid_accuracy, "\n test accuracy: ", test_accuracy
    print((self.mean))
    plot_digits(self.mean)
    plt.savefig("2.4 mean.png")
    plt.clf()
    plot_digits(self.var)
    plt.savefig("2.4 variance.png")
    plt.clf()
Ejemplo n.º 2
0
def main():
    """
    Learn a Naive Bayes classifier on the digit dataset, evaluate its
    performance on training and test sets, then visualize the mean and variance
    for each class.
    """

    nbc = NaiveBayesClassifier()
    nbc.train(load_train()[0], load_train()[1])
    print 'Training accuracy: %.4f Test accuracy: %.4f' % (
        nbc.compute_accuracy(load_train()[0],
                             load_train()[1]),
        nbc.compute_accuracy(load_test()[0],
                             load_test()[1]))
    plot_digits(nbc.mean)
    plot_digits(nbc.var)
    '''
Ejemplo n.º 3
0
def main():
    """
    Learn a Naive Bayes classifier on the digit dataset, evaluate its
    performance on training and test sets, then visualize the mean and variance
    for each class.
    """
    
    train_inputs, train_targets = load_train()
    test_inputs, test_targets = load_test()

    # add your code here (it should be less than 10 lines)
    NB = NaiveBayesClassifier()
    NB.train(train_inputs, train_targets)
    print(NB.compute_accuracy(train_inputs, train_targets))
    print(NB.compute_accuracy(test_inputs, test_targets))
    plot_digits(NB.mean)
    plot_digits(NB.var)
Ejemplo n.º 4
-1
def main():
    """
    Learn a Naive Bayes classifier on the digit dataset, evaluate its
    performance on training and test sets, then visualize the mean and variance
    for each class.
    """
    
    nbc = NaiveBayesClassifier()
    nbc.train(load_train()[0],load_train()[1])
    print 'Training accuracy: %.4f Test accuracy: %.4f' % (nbc.compute_accuracy(load_train()[0],load_train()[1]), nbc.compute_accuracy(load_test()[0],load_test()[1]))
    plot_digits(nbc.mean)
    plot_digits(nbc.var)

    '''
Ejemplo n.º 5
-1
def main():
    """
    Learn a Naive Bayes classifier on the digit dataset, evaluate its
    performance on training and test sets, then visualize the mean and variance
    for each class.
    """
    
    train_inputs, train_targets = load_train()
    test_inputs, test_targets = load_test()
    nbc = NaiveBayesClassifier()
    nbc.train(train_inputs, train_targets)
    acc = nbc.compute_accuracy(test_inputs, test_targets)
    print "the accuracy is {}".format(acc)
    plot_digits(nbc.mean)
    plot_digits(nbc.var)
Ejemplo n.º 6
-1
Archivo: nb.py Proyecto: blackle/Year_4
def main():
    """
    Learn a Naive Bayes classifier on the digit dataset, evaluate its
    performance on training and test sets, then visualize the mean and variance
    for each class.
    """
    
    train_inputs, train_targets = load_train()
    test_inputs, test_targets = load_test()

    my_model = NaiveBayesClassifier()
    my_model.train(train_inputs, train_targets)
    print "training accuracy: %.1f%%\ntest accuracy %.1f%%" % \
        (100.0*my_model.compute_accuracy(train_inputs, train_targets), \
         100.0*my_model.compute_accuracy(test_inputs, test_targets))

    plot_digits( np.concatenate((my_model.mean, my_model.var), axis=0) )
Ejemplo n.º 7
-1
Archivo: nb.py Proyecto: tianrui/CSC411
def main():
    """
    Learn a Naive Bayes classifier on the digit dataset, evaluate its
    performance on training and test sets, then visualize the mean and variance
    for each class.
    """
    
    train_inputs, train_targets = load_train()
    test_inputs, test_targets = load_test()
    
    # add your code here (it should be less than 10 lines)
    classifier = NaiveBayesClassifier()
    while (not classifier.model_learned):
        classifier.train(train_inputs, train_targets)
    print 'Training accuracy: ', classifier.compute_accuracy(train_inputs, train_targets)
    print 'Test accuracy: ', classifier.compute_accuracy(test_inputs, test_targets)
    plot_digits(classifier.mean)
Ejemplo n.º 8
-1
def main():
    """
    Learn a Naive Bayes classifier on the digit dataset, evaluate its
    performance on training and test sets, then visualize the mean and variance
    for each class.
    """
    
    train_inputs, train_targets = load_train()
    test_inputs, test_targets = load_test()

    # add your code here (it should be less than 10 lines)
    
    nbc = NaiveBayesClassifier()
    nbc.train(train_inputs, train_targets)
    print nbc.compute_accuracy(test_inputs, test_targets)
    print nbc.compute_accuracy(train_inputs, train_targets)
    plot_digits(nbc.mean.reshape((2,784)))
    plot_digits(nbc.var.reshape((2,784)))