我正在使用GBDT来自sklearn,我想知道是否有方法可以获取最终训练后的GBDT树信息?我理解,如果我设置最大500棵树,每棵树最大深度为10,这是一个上限,我想知道实际使用的树的数量,以及每棵树的实际深度。
回答:
您链接的文档页面列出了以下属性:
estimators_ : ndarray of DecisionTreeRegressor,shape (n_estimators, loss_.K) The collection of fitted sub-estimators. loss_.K is 1 for binary classification, otherwise n_classes.
因此,您应该能够按它们添加到模型的顺序获取各个树。
附加评论:模型中实际使用的树的数量将等于参数n_estimators
,除非使用了提前停止,在这种情况下,数量可能会更少,并且存储在以下属性中:
n_estimators_ : int The number of estimators as selected by early stopping (if n_iter_no_change is specified). Otherwise it is set to n_estimators
深度是最大化的,除非每个叶子/分支的样本不足和其他参数限制。