class DecisionNode():
“”"Class that represents a decision node or leaf in the decision tree
Parameters:
feature_i: int
Feature index which we want to use as the threshold measure.
threshold: float
The value that we will compare feature values at feature_i against to
determine the prediction.
value: float
The class prediction if classification tree, or float value if regression tree.
true_branch: DecisionNode
Next decision node for samples where features value met the threshold.
false_branch: DecisionNode
Next decision node for samples where features value did not meet the threshold.
“”"
def init(self, feature_i=None, threshold=None,
value=None, true_branch=None, false_branch=None):
self.feature_i = feature_i # Index for the feature that is tested
self.threshold = threshold # Threshold value for feature
self.value = value # Value if the node is a leaf in the tree
self.true_branch = true_branch # ‘Left’ subtree
self.false_branch = false_branch # ‘Right’ subtree
Super class of RegressionTree and ClassificationTree
class DecisionTree(object):
“”"Super class of RegressionTree and ClassificationTree.
Parameters:
min_samples_split: int
The minimum number of samples needed to make a split when building a tree.
min_impurity: float
The minimum impurity required to split the tree further.
max_depth: int
The maximum depth of a tree.
loss: function
Loss function that is used for Gradient Boosting models to calculate impurity.
“”"
def init(self, min_samples_split=2, min_impurity=1e-7,
max_depth=float(“inf”), loss=None):
self.root = None # Root node in dec. tree
Minimum n of samples to justify split
self.min_samples_split = min_samples_split