Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add capability to get possible max and min values for a model #2737

Merged
merged 26 commits into from
Feb 20, 2020
Merged
Changes from 1 commit
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
971720f
Add capability to get possible max and min values for a model
JoanFM Feb 3, 2020
3c49f4c
Change implementation to have return value in tree.cpp, change naming…
JoanFM Feb 4, 2020
48a9474
Update include/LightGBM/c_api.h
JoanFM Feb 5, 2020
0d516c1
Change iteration to avoid potential overflow, add bindings to R and P…
JoanFM Feb 5, 2020
f14ca1f
Merge branch 'master' of https://github.com/microsoft/LightGBM into m…
Feb 5, 2020
8c58493
Adjust test values
Feb 5, 2020
019bda8
Consider const correctness and multithreading protection
JoanFM Feb 5, 2020
c43bf1c
Update test values
Feb 6, 2020
cfa612b
Update test values
Feb 6, 2020
d3a54ae
Add test to check that model is exactly the same in all platforms
JoanFM Feb 8, 2020
8ae8f3e
Try to parse the model to get the expected values
JoanFM Feb 8, 2020
3713151
Try to parse the model to get the expected values
JoanFM Feb 8, 2020
1cd8a9d
Merge branch 'max_min_leafs' of https://github.com/JoanFM/LightGBM in…
JoanFM Feb 8, 2020
c7185a0
Fix implementation, num_leaves can be lower than the leaf_value_ size
JoanFM Feb 9, 2020
fd0bdb8
Do not check for num_leaves to be smaller than actual size and get ba…
JoanFM Feb 9, 2020
d6ca4ff
Merge branch 'max_min_leafs' of https://github.com/JoanFM/LightGBM in…
JoanFM Feb 12, 2020
a753edf
Merge branch 'master' of https://github.com/microsoft/LightGBM into m…
JoanFM Feb 12, 2020
19234e0
Change test order
JoanFM Feb 12, 2020
00bdde1
Add gpu_use_dp option in test
JoanFM Feb 13, 2020
82c677c
Remove helper test method
JoanFM Feb 13, 2020
cb94fe1
Update src/c_api.cpp
JoanFM Feb 17, 2020
136237e
Update src/io/tree.cpp
JoanFM Feb 17, 2020
c39c32f
Update src/io/tree.cpp
JoanFM Feb 17, 2020
a36be1e
Update tests/python_package_test/test_basic.py
JoanFM Feb 17, 2020
d8abaa7
Remoove imports
Feb 17, 2020
aa362e6
Merge branch 'max_min_leafs' of https://github.com/JoanFM/LightGBM in…
Feb 17, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Remove helper test method
  • Loading branch information
JoanFM authored and joanfontanals committed Feb 13, 2020
commit 82c677c75ec80be60f2a118ffe4cd6a705ecd730
46 changes: 0 additions & 46 deletions tests/python_package_test/test_basic.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,48 +13,6 @@
import operator


def find_upper_and_lower_bounds(bst):
class _max:
def __lt__(self, other):
return False

def __gt__(self, other):
return True

class _min:
def __lt__(self, other):
return True

def __gt__(self, other):
return False

MAX, MIN = _max(), _min()

def find_bound_value_in_tree(tree, bound_value, op):
bound_candidate = bound_value
if ('left_child' in tree):
bound_candidate = find_bound_value_in_tree(tree['left_child'], bound_candidate, op)
if ('right_child' in tree):
bound_candidate = find_bound_value_in_tree(tree['right_child'], bound_candidate, op)
if ('leaf_value' in tree):
leaf_value = float(tree['leaf_value'])
if (op(leaf_value, bound_candidate)):
return leaf_value
else:
return bound_candidate
return bound_candidate

result_dict = json.loads(json.dumps(bst.dump_model()))
expected_upper_bound = 0.0
expected_lower_bound = 0.0
tree_info = result_dict['tree_info']
for item in tree_info:
tree = item['tree_structure']
expected_upper_bound += find_bound_value_in_tree(tree, MIN, operator.gt)
expected_lower_bound += find_bound_value_in_tree(tree, MAX, operator.lt)
return (expected_lower_bound, expected_upper_bound)


class TestBasic(unittest.TestCase):

def test(self):
Expand All @@ -81,14 +39,10 @@ def test(self):
if i % 10 == 0:
print(bst.eval_train(), bst.eval_valid())

(lower_bound, upper_bound) = find_upper_and_lower_bounds(bst)

self.assertEqual(bst.current_iteration(), 20)
self.assertEqual(bst.num_trees(), 20)
self.assertEqual(bst.num_model_per_iteration(), 1)
self.assertAlmostEqual(bst.lower_bound(), lower_bound)
self.assertAlmostEqual(bst.lower_bound(), -2.9040190126976606)
self.assertAlmostEqual(bst.upper_bound(), upper_bound)
self.assertAlmostEqual(bst.upper_bound(), 3.3182142872462883)

bst.save_model("model.txt")
Expand Down