|
8 | 8 | import numpy as np |
9 | 9 | import scipy.sparse as sp |
10 | 10 |
|
11 | | -from Orange.preprocess import discretize, Discretize |
| 11 | +from Orange.preprocess import discretize, Discretize, decimal_binnings |
12 | 12 | from Orange import data |
13 | 13 | from Orange.data import Table, Instance, Domain, ContinuousVariable, DiscreteVariable |
14 | 14 |
|
@@ -95,6 +95,34 @@ def test_equalwidth_const_value(self): |
95 | 95 | self.assertEqual(dvar.compute_value.points, []) |
96 | 96 |
|
97 | 97 |
|
| 98 | +class TestBinning(TestCase): |
| 99 | + def test_decimal_binnings(self): |
| 100 | + values = np.array([ |
| 101 | + -0.2, -0.2, -0.6, 1.0, 0.2, -0.6, 0.6, 1.0, 0.4, -0.5, -0.4, -0.4, |
| 102 | + -0.6, 0.6, 0.75, 0.4, -0.2, 0.2, 0.0, 0.0, -1.0, -0.6, -0.2, -0.6, |
| 103 | + ]) |
| 104 | + binning = decimal_binnings(values, factors=[0.2, 0.25, 0.5]) |
| 105 | + self.assertEqual(len(binning), 3) |
| 106 | + |
| 107 | + np.testing.assert_array_equal( |
| 108 | + binning[0].thresholds, |
| 109 | + [-1, -0.8, -0.6, -0.4, -0.2, 0, 0.2, 0.4, 0.6, 0.8, 1] |
| 110 | + ) |
| 111 | + self.assertEqual(binning[0].width, 0.2) |
| 112 | + |
| 113 | + np.testing.assert_array_equal( |
| 114 | + binning[1].thresholds, |
| 115 | + [-1, -0.75, -0.5, -0.25, 0, 0.25, 0.5, 0.75, 1] |
| 116 | + ) |
| 117 | + self.assertEqual(binning[1].width, 0.25) |
| 118 | + |
| 119 | + np.testing.assert_array_equal( |
| 120 | + binning[2].thresholds, |
| 121 | + [-1, -0.5, 0, 0.5, 1] |
| 122 | + ) |
| 123 | + self.assertEqual(binning[2].width, 0.5) |
| 124 | + |
| 125 | + |
98 | 126 | # noinspection PyPep8Naming |
99 | 127 | class TestEntropyMDL(TestCase): |
100 | 128 | def test_entropy_with_two_values(self): |
|
0 commit comments