Skip to content

Instantly share code, notes, and snippets.

@MarkEdmondson1234
Last active September 28, 2015 12:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save MarkEdmondson1234/da4c9c3fb7bfc3aeeea6 to your computer and use it in GitHub Desktop.
Save MarkEdmondson1234/da4c9c3fb7bfc3aeeea6 to your computer and use it in GitHub Desktop.
library(randomForest)
## warning - can take a long time (30mins)
rf <- randomForest(x = predictors, y = response)
## once model done, we run it using test data and compare results to reality
predictor_test <- test[,which(!names(test) %in% c("dimension1","boughtSku"))]
response_test <- as.factor(test[,"boughtSku"])
## check result on test set
prediction <- predict(rf, predictor_test)
predictor_test$correct <- as.character(prediction) == as.character(response_test)
## How many were correct?
table(as.character(prediction) == as.character(response_test))
accuracy <- sum(predictor_test$correct) / nrow(predictor_test)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment