Skip to content

Commit 740aae4

Browse files
committed
improve testing
1 parent 79da5b5 commit 740aae4

File tree

2 files changed

+16
-6
lines changed

2 files changed

+16
-6
lines changed

_unittests/ut_mlmodel/test_piecewise_decision_tree_experiment.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
_test_criterion_node_impurity_children,
1313
_test_criterion_update,
1414
_test_criterion_node_value,
15+
_test_criterion_printf,
1516
_test_criterion_proxy_impurity_improvement,
1617
_test_criterion_impurity_improvement,
1718
)
@@ -120,8 +121,15 @@ def test_criterions(self):
120121
self.assertEqual(v1, v2)
121122
p1 = _test_criterion_impurity_improvement(c1, 0.0, left1, right1)
122123
p2 = _test_criterion_impurity_improvement(c2, 0.0, left2, right2)
123-
# print(left1, right1, "*", left2, right2)
124-
# print(c2.printd())
124+
self.assertIn(
125+
"value: 1.500000 total=0.260000 left=0.000000 right=0.186667",
126+
_test_criterion_printf(c1),
127+
)
128+
self.assertIn(
129+
"value: 1.500000 total=0.260000 left=0.000000 right=0.186667",
130+
_test_criterion_printf(c2),
131+
)
132+
self.assertEqual(_test_criterion_printf(c1), _test_criterion_printf(c2))
125133
self.assertAlmostEqual(p1, p2, atol=1e-10)
126134

127135
X = numpy.array([[1.0, 2.0, 10.0, 11.0]]).T

mlinsights/mlmodel/_piecewise_tree_regression_common.pyx

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -308,13 +308,15 @@ def _test_criterion_update(Criterion criterion, SIZE_t new_pos):
308308

309309
def _test_criterion_printf(Criterion crit):
310310
"Test purposes. Methods cannot be directly called from python."
311-
printf("start=%zu pos=%zu end=%zu\n", crit.start, crit.pos, crit.end)
312311
cdef DOUBLE_t left, right, value
313312
cdef int i
314313
crit.children_impurity(&left, &right)
315314
crit.node_value(&value)
316-
printf("value: %f total=%f left=%f right=%f\n", value,
317-
crit.node_impurity(), left, right)
315+
rows = []
316+
rows.append("start=%d pos=%d end=%d" % (crit.start, crit.pos, crit.end))
317+
rows.append("value: %f total=%f left=%f right=%f" % (
318+
value, crit.node_impurity(), left, right))
318319
cdef int n = crit.y.shape[0]
319320
for i in range(0, n):
320-
printf("-- %d: y=%f\n", i, crit.y[i, 0])
321+
rows.append("-- %d: y=%f" % (i, crit.y[i, 0]))
322+
return "\n".join(rows)

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy