sklearn源码解析:ensemble模型 零碎记录;如何看sklearn代码,以tree的feature_importance为例



最近看sklearn的源码比较多,好记性不如烂笔头啊,还是记一下吧。



整体:

)实现的代码非常好,模块化、多继承等写的很清楚。

)predict功能通常在该模型的直接类中实现,fit通常在继承的类中实现,方便不同的子类共同引用。





随机森林 和 GBDT

)RandomForest的bootstrap是又放回的;GBDT则是无放回的。

)实现的代码非常好,比如GBDT提供了一些小白不常用的函数【staged_decision_function,staged_predict】之类,对于调试观察每个DT的输出非常有帮助。

)大多数模型的predict都依赖于predict_proba返回的proba,但GBDT的predict依赖于decision_function返回的score,但本质一样,仅记录一下。

)还没观察adaboost如何实现,但GBDT给人的感觉是,这种串行训练模型一般在fit中调用_fit_stages,所以看源码知道重点了吧。GBDT在https://github.com/scikit-learn/scikit-learn/blob/51a765a/sklearn/ensemble/gradient_boosting.py#L747的_fit_stage才是真正的训练函数、L763中给出了训练时使用的base tree是【tree= DecisionTreeRegressor(...)

In random forests (see RandomForestClassifier and RandomForestRegressor classes), each tree in the ensemble is built from a sample drawn with replacement (i.e., a bootstrap sample) from the training set. In addition, when splitting a node during the construction of the tree, the split that is chosen is no longer the best split among all features. Instead, the split that is picked is the best split among a random subset of the features. ===》 训练树之前,bootstrap出样本,训练每个节点时,才sample特征。。。。。

In extremely randomized trees (see ExtraTreesClassifier and 

  • 6
    点赞
  • 19
    收藏
    觉得还不错? 一键收藏
  • 6
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 6
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值