Numpy实现DecisionTree(2)

本文介绍了XGBoost库中的决策树类,包括DecisionNode和DecisionTree,详细解释了节点结构(特征值比较、阈值决定分支)以及决策树的构建过程。文章着重展示了如何使用这些类进行分类和回归任务的预测,并提到了XGBoostRegressionTree的特性和用途。
摘要由CSDN通过智能技术生成

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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值