Skip to content

Instantly share code, notes, and snippets.

@glamp
Created September 22, 2013 20:11
Show Gist options
  • Save glamp/6663325 to your computer and use it in GitHub Desktop.
Save glamp/6663325 to your computer and use it in GitHub Desktop.
library(randomForest)
library(miscTools)
library(ggplot2)
cols <- c('is_red', 'fixed.acidity', 'density', 'pH', 'alcohol')
rf <- randomForest(alcohol ~ ., data=train[,cols], ntree=20)
(r2 <- rSquared(test$alcohol, test$alcohol - predict(rf, test[,cols])))
# [1] 0.6481
(mse <- mean((test$alcohol - predict(rf, test[,cols]))^2))
# [1] 0.6358
p <- ggplot(aes(x=actual, y=pred),
data=data.frame(actual=test$alcohol, pred=predict(rf, test[,cols])))
p + geom_point() +
geom_abline(color="red") +
ggtitle(paste("RandomForest Regression in R r^2=", r2, sep=""))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment