def test_random_forest_5_trees(self): learner = dt.RandomForest(num_trees=5, depth_limit=5, example_subsample_rate=0.5, attr_subsample_rate=0.5) learner.fit(self.train_features, self.train_classes) output = learner.classify(self.train_features) result = dt.confusion_matrix(output, self.train_classes) print "\n\nconfusion_matrix={}".format(result) print "accuracy={}".format(dt.accuracy(output, self.train_classes)) print "precision={}".format(dt.precision(output, self.train_classes)) print "recall={}".format(dt.recall(output, self.train_classes))
def test_confusion_matrix(self): """Test confusion matrix for the example tree. Asserts: confusion matrix is correct. """ answer = [1, 0, 0, 1, 0, 0, 0] true_label = [1, 1, 1, 0, 0, 0, 0] test_matrix = [[1, 2], [1, 3]] confusion_matrix = dt.confusion_matrix(answer, true_label) assert np.array_equal(test_matrix, confusion_matrix)
def test_random_forest_5_trees(self): path = abspath("challenge_train.csv") self.train_features, self.train_classes = dt.load_csv(path, 0) #print classes # learner = dt.ChallengeClassifier() # learner.fit(features, classes) # output = learner.classify(features) # print output # result = dt.confusion_matrix(output, classes) # print "\n\nconfusion_matrix={}".format(result) # print "accuracy={}".format(dt.accuracy(output, classes)) # print "precision={}".format(dt.precision(output, classes)) # print "recall={}".format(dt.recall(output, classes)) learner = dt.ChallengeClassifier() learner.fit(self.train_features, self.train_classes) output = learner.classify(self.train_features) print output result = dt.confusion_matrix(output, self.train_classes) print "\n\nconfusion_matrix={}".format(result) print "accuracy={}".format(dt.accuracy(output, self.train_classes)) print "precision={}".format(dt.precision(output, self.train_classes)) print "recall={}".format(dt.recall(output, self.train_classes))