admin管理员组

文章数量:1650773



最近看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 

本文标签: 零碎为例源码如何看模型