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
用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