Created
January 29, 2020 04:49
-
-
Save arpitbbhayani/622e9ec5389e5ecc3e669a51619b4179 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def get_path_length(x, T, e): | |
"""The function returns the path length h(x) of an instance | |
x in tree `T`. | |
here e is the number of edges traversed from the root till the current | |
subtree T. | |
""" | |
if is_external_node(T): | |
# when T is the root of an external node subtree | |
# we estimate path length and return. | |
# here c is the function which estimates the average path length | |
# for external node termination. | |
return e + c(len(T)) | |
# T is the root of an internal node then we | |
if x[T.split_attribute] < T[split_value]: | |
# instance x may lie in left subtree | |
return get_path_length(x, T.left, e + 1) | |
else: | |
# instance x may lie in right subtree | |
return get_path_length(x, T.right, e + 1) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment