Out of bag error in Random Forest

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/Gavin__Zhou/article/details/77184765

sklearn中的RandomForestClassifier有一个参数:

oob_score : bool (default=False)
Whether to use out-of-bag samples to estimate the generalization accuracy.

中文叫‘袋外误差’,可以看出这个参数的意思是:使用oob来衡量test error.


关于oob的解释,stackoverflow上有比较全面的解释:OOB的解释
说下自己的理解:

  • RF需要从原始的特征集中随机sampling,然后去分裂生成单颗树.
  • 每个树的训练样本是从原始的训练集boostraping而来.
  • 由于boostraping的有放回抽样方式,导致每个树的训练集合不同且只是原始训练集的一个部分.
  • 对于第t个树来说,原始训练集中那些不在第t个树的训练集的数据,可以使用第t个树来进行test.
  • 现在生成n(n是原始数据集的大小)个树,每个树的训练样本大小为n-1,对第i个树来说其训练集不包含(xi,yi)这个样本.
  • 使用不包含(xi,yi)这个样本的所有的树(n-1个),vote的结果作为最终(xi,yi)这个样本的test结果.

这样就可以在训练的时候来进行测试了,经验表明:

out-of-bag estimate is as accurate as using a test set of the same size as the training set.

意思就是,oob是test error的一个无偏估计.

一句话总结下: 假设Zi=(xi,yi)

The out-of-bag (OOB) error is the average error for each Zi calculated using predictions from the trees that do not contain Zi in their respective bootstrap sample. This allows the RandomForestClassifier to be fit and validated whilst being trained.


参考

stackoverflow上OOB的解释
sklearn上OOB的解释

猜你喜欢

转载自blog.csdn.net/Gavin__Zhou/article/details/77184765
今日推荐