通过源码分析GBDT是怎么实现early stopping的

本文深入分析GBDT的源码,探讨如何实现早期停止策略。通过对比有无early stopping的情况,展示了该策略对模型性能的影响。文中详细解释了关键代码段,并给出了不同参数设置下的效果比较。
摘要由CSDN通过智能技术生成

GBDT文档:Early stopping of Gradient Boosting

源码分析

有无early stopping的比较

    gbes = ensemble.GradientBoostingClassifier(n_estimators=n_estimators,
                                               validation_fraction=0.2,
                                               n_iter_no_change=5, tol=0.01,
                                               random_state=0)
    gb = ensemble.GradientBoostingClassifier(n_estimators=n_estimators,
                                             random_state=0)

打开scikit-learn源码,看到sklearn.ensemble._gb.GradientBoostingClassifier

尝试用Example作为调试入口:examples/ensemble/plot_gradient_boosting_early_stopping.py

尝试失败。Cython和cpp项目就是难搞。

看到他的基类sklearn.ensemble._gb.BaseGradientBoosting#fit

sklearn/ensemble/_gb.py:424

        if self.n_iter_no_change is not None:
            stratify = y if is_classifier(self) else None
            X, X_val, y, y_val, sample_weight, sample_weight_val = (
                train_test_split(X, y, sample_weight,
                                 random_state=self.random_state,
                                 test_size=self.validation_fraction,
                                 stratify=stratify))
            if is_classifier(self):
                if self.
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值