Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Getting random forest prediction accuracy for a continuous variable in R

I'm trying to predict a continuous variable (count) in R with random forest. The values of the predicted variable are min=1 and max=1000.

I tried getting the prediction accuracy with "confusionMatrix", but naturally I get the error of different number of levels between the prediction and the predicted.

What is the best method of getting prediction accuracy in these circumstances?

like image 634
mishakob Avatar asked Oct 24 '25 06:10

mishakob


1 Answers

@ mishakob

Roughly speaking, the root mean squared error can be understood as normalized deviance between actual and fitted values. it can be obtained as following.

library(randomForest)
set.seed(1237)
iris.rg <- randomForest(Sepal.Length ~ ., data=iris, importance=TRUE,
                        proximity=TRUE)

sqrt(sum((iris.rg$predicted - iris$Sepal.Length)^2) / nrow(iris))
[1] 0.3706187
like image 107
Jaehyeon Kim Avatar answered Oct 25 '25 21:10

Jaehyeon Kim



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!