R语言 random forests out-of-bag prediction

out-of-bag prediction

Created: Jun 29, 2020 12:22 PM
Updated: Jun 29, 2020 12:28 PM

https://stackoverflow.com/questions/25153276/difference-of-prediction-results-in-random-forest-model

https://stats.stackexchange.com/questions/412479/difference-between-the-out-of-bag-error-and-the-predicted-error

用R语言算random forests的时候发现,训练数据的model$predictions不等于predict(model, train_data)

这其实是一个与out-of-bag有关的合理设计。model$predictions给出的训练数据的预测值,是out-of-bag predictions,也就是对于每个point,**进行预测的时候包含这个point的tree会被排除在外!**random forests中每个tree训练的时候只用于2/3的数据,所以进行out-of-bag预测的时候,只会用到random forests中1/3的tree进行预测。

因此,下面的结果是不同的:

predict(model)
predict(model, newdata=dat)

第一种情况下,默认使用out-of-bag predictions。第二种数据下,由于提供了newdata(虽然是训练数据本身),dat会被当成测试数据,而不再是训练数据,因此进行的完整的预测,而不是只用1/3的tree进行预测的out-of-bag predictions

原文地址:https://www.cnblogs.com/yaos/p/14014127.html