Beispiel #1
0
    def testSetMaxDepth(self):
        maxDepth = 20
        randomForest = RandomForest()
        randomForest.setMaxDepth(maxDepth)
        randomForest.learnModel(self.X, self.y)

        #self.assertTrue(RandomForest.depth(randomForest.getClassifier().tree) <= maxDepth+1)

        maxDepth = 5
        randomForest = RandomForest()
        randomForest.setMaxDepth(maxDepth)
        randomForest.learnModel(self.X, self.y)
Beispiel #2
0
    def testSetMaxDepth(self):
        maxDepth = 20
        randomForest = RandomForest()
        randomForest.setMaxDepth(maxDepth)
        randomForest.learnModel(self.X, self.y)

        #self.assertTrue(RandomForest.depth(randomForest.getClassifier().tree) <= maxDepth+1)

        maxDepth = 5
        randomForest = RandomForest()
        randomForest.setMaxDepth(maxDepth)
        randomForest.learnModel(self.X, self.y)
Beispiel #3
0
    def testSetWeight(self):
        #Try weight = 0 and weight = 1
        randomForest = RandomForest()
        randomForest.setWeight(0.0)
        randomForest.learnModel(self.X, self.y)

        predY = randomForest.predict(self.X)
        self.assertTrue((predY == numpy.zeros(predY.shape[0])).all())

        randomForest.setWeight(1.0)
        randomForest.learnModel(self.X, self.y)
        predY = randomForest.predict(self.X)
        self.assertTrue((predY == numpy.ones(predY.shape[0])).all())
Beispiel #4
0
    def testSetWeight(self):
        #Try weight = 0 and weight = 1
        randomForest = RandomForest()
        randomForest.setWeight(0.0)
        randomForest.learnModel(self.X, self.y)

        predY = randomForest.predict(self.X)
        self.assertTrue((predY == numpy.zeros(predY.shape[0])).all())

        randomForest.setWeight(1.0)
        randomForest.learnModel(self.X, self.y)
        predY = randomForest.predict(self.X)
        self.assertTrue((predY == numpy.ones(predY.shape[0])).all())
Beispiel #5
0
    def testPredict(self):
        randomForest = RandomForest()
        randomForest.learnModel(self.X, self.y)
        predY = randomForest.predict(self.X)

        inds = numpy.random.permutation(self.X.shape[0])
        predY2 = randomForest.predict(self.X[inds, :])

        self.assertTrue((predY[inds] == predY2).all())

        #Let's test on -1, +1 labels
        y2 = (self.y * 2) - 1
        randomForest.learnModel(self.X, y2)
        predY2 = randomForest.predict(self.X)

        self.assertTrue((predY2 == predY * 2 - 1).all())
Beispiel #6
0
    def testPredict(self):
        randomForest = RandomForest()
        randomForest.learnModel(self.X, self.y)
        predY = randomForest.predict(self.X)

        inds = numpy.random.permutation(self.X.shape[0])
        predY2 = randomForest.predict(self.X[inds, :])

        self.assertTrue((predY[inds] == predY2).all())

        #Let's test on -1, +1 labels
        y2 = (self.y*2)-1
        randomForest.learnModel(self.X, y2)
        predY2 = randomForest.predict(self.X)

        self.assertTrue((predY2 == predY*2-1).all())
Beispiel #7
0
    def testLearnModel(self):
        randomForest = RandomForest()
        randomForest.learnModel(self.X, self.y)

        tree = randomForest.getClassifier()
Beispiel #8
0
    def testLearnModel(self):
        randomForest = RandomForest()
        randomForest.learnModel(self.X, self.y)

        tree = randomForest.getClassifier()