Skip to content

Commit 5e055e0

Browse files
committed
Fixing get_leaves function and better documentation
1 parent a372c5c commit 5e055e0

29 files changed

+3891
-3091
lines changed

.readthedocs.yaml

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,22 @@
1+
# .readthedocs.yaml
2+
# Read the Docs configuration file
3+
# See https://docs.readthedocs.io/en/stable/config-file/v2.html for details
4+
5+
# Required
16
version: 2
27

8+
# Set the version of Python and other tools you might need
39
build:
410
os: ubuntu-22.04
511
tools:
6-
python: "3.10"
12+
python: "3.11"
713

14+
# Build documentation in the docs/ directory with Sphinx
815
sphinx:
916
configuration: docs/conf.py
17+
18+
# We recommend specifying your dependencies to enable reproducible builds:
19+
# https://docs.readthedocs.io/en/stable/guides/reproducible-builds.html
20+
python:
21+
install:
22+
- requirements: docs/requirements.txt

HISTORY.rst

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,12 @@
33
History
44
-------
55

6+
9.8.0 (2024-09-09)
7+
------------------
8+
9+
- Fixing the get_leaves function for local decision trees.
10+
- Changing documentation templates.
11+
612
9.8.0.dev1 (2024-02-28)
713
-----------------------
814

bigml/generators/model.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -135,8 +135,9 @@ def get_leaves(model, path=None, filter_function=None):
135135

136136
offsets = model.offsets
137137

138-
def get_tree_leaves(tree, fields, path, leaves, filter_function=None):
138+
def get_tree_leaves(tree, fields, path, filter_function=None):
139139

140+
leaves = []
140141
node = get_node(tree)
141142
predicate = get_predicate(tree)
142143
if isinstance(predicate, list):
@@ -149,10 +150,12 @@ def get_tree_leaves(tree, fields, path, leaves, filter_function=None):
149150

150151
if children:
151152
for child in children:
153+
152154
leaves += get_tree_leaves(child, fields,
153-
path[:], leaves,
155+
path[:],
154156
filter_function=filter_function)
155157
else:
158+
print("id:", node[offsets["id"]])
156159
leaf = {
157160
'id': node[offsets["id"]],
158161
'confidence': node[offsets["confidence"]],
@@ -171,7 +174,7 @@ def get_tree_leaves(tree, fields, path, leaves, filter_function=None):
171174
or filter_function(leaf)):
172175
leaves += [leaf]
173176
return leaves
174-
return get_tree_leaves(model.tree, model.fields, path, leaves,
177+
return get_tree_leaves(model.tree, model.fields, path,
175178
filter_function)
176179

177180

bigml/tests/create_model_steps.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
from bigml.deepnet import Deepnet
3232
from bigml.fusion import Fusion
3333
from bigml.ensemble import Ensemble
34+
from bigml.generators.model import get_leaves
3435

3536

3637
from .read_resource_steps import wait_until_status_code_is
@@ -690,3 +691,8 @@ def the_cloned_logistic_regression_is(step, logistic_regression):
690691
def check_deepnet_id_local_id(step):
691692
"""Checking that deepnet ID and local deepnet ID match"""
692693
eq_(world.deepnet["resource"], step.bigml["local_deepnet"].resource_id)
694+
695+
696+
def check_leaves_number(step, leaves_number):
697+
"""Checking the number of leaves in a tree local model"""
698+
eq_(len(get_leaves(step.bigml["local_model"])), leaves_number)

bigml/tests/test_40_local_from_file.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -66,17 +66,18 @@ def test_scenario1(self):
6666
When I create a local model from the file "<exported_file>"
6767
Then the model ID and the local model ID match
6868
And the prediction for "<input_data>" is "<prediction>"
69+
And the number of leaves is "<leaves#>"
6970
"""
7071
show_doc(self.test_scenario1)
7172
headers = ["data", "source_wait", "dataset_wait", "model_wait",
7273
"pmml", "exported_file", "input_data", "prediction",
73-
"model_conf"]
74+
"model_conf", 'leaves#']
7475
examples = [
7576
['data/iris.csv', '10', '10', '10', False,
76-
'./tmp/model.json', {}, "Iris-setosa", '{}'],
77+
'./tmp/model.json', {}, "Iris-setosa", '{}', 9],
7778
['data/iris.csv', '10', '10', '10', False,
7879
'./tmp/model_dft.json', {}, "Iris-versicolor",
79-
'{"default_numeric_value": "mean"}']]
80+
'{"default_numeric_value": "mean"}', 9]]
8081
for example in examples:
8182
example = dict(zip(headers, example))
8283
show_method(self, self.bigml["method"], example)
@@ -97,6 +98,7 @@ def test_scenario1(self):
9798
model_create.check_model_id_local_id(self)
9899
model_create.local_model_prediction_is(
99100
self, example["input_data"], example["prediction"])
101+
model_create.check_leaves_number(self, example["leaves#"])
100102

101103
def test_scenario2(self):
102104
"""

bigml/version.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
__version__ = '9.8.0.dev1'
1+
__version__ = '9.8.0'

docs/101_anomaly.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
.. toctree::
22
:hidden:
33

4-
BigML Bindings: 101 - Using an anomaly detector
5-
===============================================
4+
101 - Anomaly detector usage
5+
============================
66

77
Following the schema described in the `prediction workflow <api_sketch.html>`_,
88
document, this is the code snippet that shows the minimal workflow to

docs/101_association.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
.. toctree::
22
:hidden:
33

4-
BigML Bindings: 101 - Using Association Discovery
5-
=================================================
4+
101 - Association Discovery usage
5+
=================================
66

77
Following the schema described in the `prediction workflow <api_sketch.html>`_,
88
document, this is the code snippet that shows the minimal workflow to

docs/101_cluster.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
.. toctree::
22
:hidden:
33

4-
BigML Bindings: 101 - Using a Cluster
5-
=====================================
4+
101 - Cluster Usage
5+
===================
66

77
Following the schema described in the `prediction workflow <api_sketch.html>`_,
88
document, this is the code snippet that shows the minimal workflow to

docs/101_deepnet.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
.. toctree::
22
:hidden:
33

4-
BigML Bindings: 101 - Using a Deepnet Model
5-
===========================================
4+
101 - Deepnet usage
5+
===================
66

77
Following the schema described in the `prediction workflow <api_sketch.html>`_,
88
document, this is the code snippet that shows the minimal workflow to

0 commit comments

Comments
 (0)