Esempio n. 1
0
    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_precision_calculation(self):
        """Test precision calculation.

        Asserts:
            Precision matches for all true labels.
        """

        answer = [0, 0, 0, 0, 0]
        true_label = [1, 0, 0, 0, 0]

        for index in range(0, len(answer)):
            answer[index] = 1
            precision = 1 / (1 + index)
            rslt = dt.precision(answer, true_label)
            assert rslt == precision
 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))