Ejemplo n.º 1
0
 def test_load_model(self):
     X, y, _ = datasets.csv2numpy(config.get('RandomForest_test', 'traindata'))
     self.rf.fit(X, y)
     newX, _, _ = datasets.csv2numpy(config.get('RandomForest_test', 'noveldata'))
     prediction = self.rf.predict(newX)
     self.rf.save_model(config.get('RandomForest_test', 'modelfile'))
     newrf = RandomForest()
     newrf.load_model(config.get('RandomForest_test', 'modelfile'))
     self.assertTrue(numpy.array_equal(prediction, newrf.predict(newX)))
     os.remove(config.get('RandomForest_test', 'modelfile'))
Ejemplo n.º 2
0
 def test_load_model(self):
     X, y, _ = datasets.csv2numpy(
         config.get('RandomForest_test', 'traindata'))
     self.rf.fit(X, y)
     newX, _, _ = datasets.csv2numpy(
         config.get('RandomForest_test', 'noveldata'))
     prediction = self.rf.predict(newX)
     self.rf.save_model(config.get('RandomForest_test', 'modelfile'))
     newrf = RandomForest()
     newrf.load_model(config.get('RandomForest_test', 'modelfile'))
     self.assertTrue(numpy.array_equal(prediction, newrf.predict(newX)))
     os.remove(config.get('RandomForest_test', 'modelfile'))
Ejemplo n.º 3
0
 def test_constructor(self):
     _ = RandomForest()
Ejemplo n.º 4
0
 def setUp(self):
     self.rf = RandomForest()
Ejemplo n.º 5
0
class RandomForest_Test(unittest.TestCase):
    '''
    Tests for the RandomForest class.
    '''
    def setUp(self):
        self.rf = RandomForest()

    def test_constructor(self):
        _ = RandomForest()

    def test_decision_function(self):
        X, y, _ = datasets.csv2numpy(
            config.get('RandomForest_test', 'traindata'))
        self.rf.fit(X, y)
        newX, _, _ = datasets.csv2numpy(
            config.get('RandomForest_test', 'noveldata'))
        self.assertTrue(len(self.rf.decision_function(newX)) == 20)

    def test_fit(self):
        X, y, _ = datasets.csv2numpy(
            config.get('RandomForest_test', 'traindata'))
        self.rf.fit(X, y)

    def test_predict(self):
        X, y, _ = datasets.csv2numpy(
            config.get('RandomForest_test', 'traindata'))
        self.rf.fit(X, y)
        newX, _, _ = datasets.csv2numpy(
            config.get('RandomForest_test', 'noveldata'))
        self.assertTrue(len(self.rf.predict(newX)) == 20)

    def test_save_model(self):
        X, y, _ = datasets.csv2numpy(
            config.get('RandomForest_test', 'traindata'))
        self.rf.fit(X, y)
        newX, _, _ = datasets.csv2numpy(
            config.get('RandomForest_test', 'noveldata'))
        self.assertTrue(len(self.rf.predict(newX)) == 20)
        self.rf.save_model(config.get('RandomForest_test', 'modelfile'))
        os.remove(config.get('RandomForest_test', 'modelfile'))

    def test_load_model(self):
        X, y, _ = datasets.csv2numpy(
            config.get('RandomForest_test', 'traindata'))
        self.rf.fit(X, y)
        newX, _, _ = datasets.csv2numpy(
            config.get('RandomForest_test', 'noveldata'))
        prediction = self.rf.predict(newX)
        self.rf.save_model(config.get('RandomForest_test', 'modelfile'))
        newrf = RandomForest()
        newrf.load_model(config.get('RandomForest_test', 'modelfile'))
        self.assertTrue(numpy.array_equal(prediction, newrf.predict(newX)))
        os.remove(config.get('RandomForest_test', 'modelfile'))
Ejemplo n.º 6
0
 def setUp(self):
     self.rf = RandomForest()
Ejemplo n.º 7
0
class RandomForest_Test(unittest.TestCase):
    '''
    Tests for the RandomForest class.
    '''
    
    def setUp(self):
        self.rf = RandomForest()
    
    def test_constructor(self):
        _ = RandomForest()
    
    def test_decision_function(self):
        X, y, _ = datasets.csv2numpy(config.get('RandomForest_test', 'traindata'))
        self.rf.fit(X, y)
        newX, _, _ = datasets.csv2numpy(config.get('RandomForest_test', 'noveldata'))
        self.assertTrue(len(self.rf.decision_function(newX)) == 20)
    
    def test_fit(self):
        X, y, _ = datasets.csv2numpy(config.get('RandomForest_test', 'traindata'))
        self.rf.fit(X, y)
    
    def test_predict(self):
        X, y, _ = datasets.csv2numpy(config.get('RandomForest_test', 'traindata'))
        self.rf.fit(X, y)
        newX, _, _ = datasets.csv2numpy(config.get('RandomForest_test', 'noveldata'))
        self.assertTrue(len(self.rf.predict(newX)) == 20)
    
    def test_save_model(self):
        X, y, _ = datasets.csv2numpy(config.get('RandomForest_test', 'traindata'))
        self.rf.fit(X, y)
        newX, _, _ = datasets.csv2numpy(config.get('RandomForest_test', 'noveldata'))
        self.assertTrue(len(self.rf.predict(newX)) == 20)
        self.rf.save_model(config.get('RandomForest_test', 'modelfile'))
        os.remove(config.get('RandomForest_test', 'modelfile'))
    
    def test_load_model(self):
        X, y, _ = datasets.csv2numpy(config.get('RandomForest_test', 'traindata'))
        self.rf.fit(X, y)
        newX, _, _ = datasets.csv2numpy(config.get('RandomForest_test', 'noveldata'))
        prediction = self.rf.predict(newX)
        self.rf.save_model(config.get('RandomForest_test', 'modelfile'))
        newrf = RandomForest()
        newrf.load_model(config.get('RandomForest_test', 'modelfile'))
        self.assertTrue(numpy.array_equal(prediction, newrf.predict(newX)))
        os.remove(config.get('RandomForest_test', 'modelfile'))