I run random forest (using package randomForest
) on the classic titanic data. Here are the code and results.
dt_rf <- randomForest(Survived ~ ., data = train, ntree = 200)
print(dt_rf)
Call:
randomForest(formula = Survived ~ ., data = train, ntree = 200)
Type of random forest: classification
Number of trees: 200
No. of variables tried at each split: 2
OOB estimate of error rate: 15.8%
Confusion matrix:
No Yes class.error
No 401 38 0.08656036
Yes 74 196 0.27407407
Wondering is there a way to access the OOB error from the dt_rf
object? I only see error rate table by dt_rf$err.rate
. What does this table mean? How is this table different from the error rate in the printable results?
dt_rf$err.rate
OOB No Yes
[1,] 0.1785714 0.07407407 0.3666667
[2,] 0.2070588 0.12781955 0.3396226
[3,] 0.2169811 0.13719512 0.3465347
[4,] 0.2233503 0.17403315 0.3013100
[5,] 0.2154088 0.16153846 0.3008130
[6,] 0.2080838 0.14146341 0.3139535
[7,] 0.1973490 0.13397129 0.2988506
[8,] 0.2023290 0.13207547 0.3155894
[9,] 0.1873199 0.11943794 0.2958801
[10,] 0.1919771 0.12064965 0.3071161
I tried using mean
to calculate the OOB
column, but it does not match 15.8%
in the printable results.