Skip to content

Instantly share code, notes, and snippets.

@arpitbbhayani
Created January 29, 2020 04:48
Show Gist options
  • Save arpitbbhayani/a7a5fc5e2fd58a15ac39926bb49eff7e to your computer and use it in GitHub Desktop.
Save arpitbbhayani/a7a5fc5e2fd58a15ac39926bb49eff7e to your computer and use it in GitHub Desktop.
def construct_forest(X, trees_count, subsample_count):
"""The function constructs a forest from given inputs/data points X.
"""
forest = []
for i in range(0, trees_count):
# max_height is in fact the average height of the tree that would be
# constructed from given points. This acts as max_height for the
# construction because we are only interested in data points that have
# shorter-than-average path lengths, as those points are more likely
# to be anomalies.
max_height = math.ceil(math.log2(subsample_count))
# create a sample with cardinality of `subsample_count` from X
X_sample = get_sample(X, subsample_count)
# construct the decision tree from the sample
tree = construct_tree(X_sample, 0, max_height)
# add the tree to the forest
forest.append(tree)
return forest
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment