mirror of
https://github.com/Doctorado-ML/Stree_datasets.git
synced 2025-08-18 08:56:01 +00:00
Fix normalize error
This commit is contained in:
29
wodt/WODT.py
29
wodt/WODT.py
@@ -215,6 +215,35 @@ class TreeClassifier(BaseEstimator, ClassifierMixin):
|
||||
self.leaf_num = 1
|
||||
self.tree_depth = self.bulid_subtree(self.root_node)
|
||||
|
||||
def nodes_leaves(self):
|
||||
def num_leaves(node):
|
||||
leaves = 0
|
||||
nodes = 0
|
||||
nodes_left = 0
|
||||
nodes_right = 0
|
||||
leaves_left = 0
|
||||
leaves_right = 0
|
||||
if node.is_leaf:
|
||||
leaves += 1
|
||||
else:
|
||||
nodes_left, leaves_left = num_leaves(node.LChild)
|
||||
nodes_right, leaves_right = num_leaves(node.RChild)
|
||||
nodes = nodes_left + nodes_right + 1
|
||||
leaves += leaves_left + leaves_right
|
||||
return nodes, leaves
|
||||
|
||||
def compute_depth(node):
|
||||
if node.is_leaf:
|
||||
return node.depth
|
||||
return max(
|
||||
node.depth,
|
||||
compute_depth(node.LChild),
|
||||
compute_depth(node.RChild),
|
||||
)
|
||||
|
||||
self.depth_ = compute_depth(self.root_node)
|
||||
return num_leaves(self.root_node)
|
||||
|
||||
def bulid_subtree(self, node):
|
||||
if node.is_leaf:
|
||||
return node.depth
|
||||
|
Reference in New Issue
Block a user