手动计算randomForest()残差

时间:2015-10-10 13:57:21

标签: r random-forest

对我来说,在回归情况下用随机森林预测的程序是非常重要的,因为我得到了不同的结果然后内置程序:

set.seed(1)
wyn <- randomForest(y = iris[, 1], x = iris[, -1])
(wyn) #Mean of squared residuals: 0.1341068

response=predict(wyn, iris[, -1]) # is it ok ? below to lines gives different output

mean((iris[,1]-wyn$predicted)^2) #returns 0.1341068
mean((iris[,1]-response)^2) # returns 0.07259335


plot(wyn$predicted,response) # almost but not identical

我在上面使用predict()时出了什么问题?

1 个答案:

答案 0 :(得分:1)

好的,现在我知道了:

#returns out-of-bag error
mean((iris[,1]-wyn$predicted)^2) #returns 0.1341068 

#returns error calculated on whole dataset
mean((iris[,1]-response)^2) # returns 0.07259335