예제 #1
0
파일: nb.py 프로젝트: meelement/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()
    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()
예제 #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)
    '''
예제 #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)
예제 #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)

    '''
예제 #5
-1
파일: nb.py 프로젝트: Myers-Omri/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()
    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)
예제 #6
-1
파일: nb.py 프로젝트: 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) )
예제 #7
-1
파일: nb.py 프로젝트: 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)
예제 #8
-1
파일: nb.py 프로젝트: DevonWelch/School
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)))