File: test_fss.py

package info (click to toggle)
orange3 3.40.0-3
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 15,928 kB
  • sloc: python: 162,745; ansic: 622; makefile: 322; sh: 93; cpp: 77
file content (36 lines) | stat: -rw-r--r-- 1,184 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
32
33
34
35
36
import unittest
from unittest.mock import Mock

import numpy as np

from Orange.data import Domain, Table, DiscreteVariable, ContinuousVariable
from Orange.preprocess import fss


class SelectBestFeaturesTest(unittest.TestCase):
    def test_no_nice_features(self):
        method = Mock()
        method.feature_type = DiscreteVariable
        selector = fss.SelectBestFeatures(method, 5)

        domain = Domain([])
        data = Table.from_numpy(domain, np.zeros((100, 0)))
        selection = selector.score_only_nice_features(data, method)
        self.assertEqual(selection.size, 0)
        method.assert_not_called()

        domain = Domain([ContinuousVariable("x")])
        data = Table.from_numpy(domain, np.zeros((100, 1)))
        selector.decreasing = True
        selection = selector.score_only_nice_features(data, method)
        np.testing.assert_equal(selection, [float('-inf')])
        method.assert_not_called()

        selector.decreasing = False
        selection = selector.score_only_nice_features(data, method)
        np.testing.assert_equal(selection, [float('inf')])
        method.assert_not_called()


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