File: test_simple_random_forest.py

package info (click to toggle)
orange3 3.40.0-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 15,908 kB
  • sloc: python: 162,745; ansic: 622; makefile: 322; sh: 93; cpp: 77
file content (31 lines) | stat: -rw-r--r-- 1,020 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# Test methods with long descriptive names can omit docstrings
# pylint: disable=missing-docstring

import unittest
import numpy as np
import Orange
from Orange.classification import SimpleRandomForestLearner as SimpRandForestCls
from Orange.regression import SimpleRandomForestLearner as SimpRandForestReg


class TestSimpleRandomForestLearner(unittest.TestCase):
    def test_SimpleRandomForest_classification(self):
        data = Orange.data.Table('iris')
        lrn = SimpRandForestCls()
        clf = lrn(data)
        p = clf(data, clf.Probs)
        self.assertEqual(p.shape, (150, 3))
        self.assertGreaterEqual(p.min(), 0)
        self.assertLessEqual(p.max(), 1)
        np.testing.assert_almost_equal(p.sum(axis=1), np.ones(150))

    def test_SimpleRandomForest_regression(self):
        data = Orange.data.Table('housing')
        lrn = SimpRandForestReg()
        clf = lrn(data)
        p = clf(data)
        self.assertEqual(p.shape, (len(data),))


if __name__ == '__main__':
    unittest.main()