admin管理员组文章数量:1650766
最近看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/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
版权声明:本文标题:sklearn源码解析:ensemble模型 零碎记录;如何看sklearn代码,以tree的feature_importance为例 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:https://www.elefans.com/dianzi/1729534768a1205275.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论