Last active
September 28, 2015 12:43
-
-
Save MarkEdmondson1234/da4c9c3fb7bfc3aeeea6 to your computer and use it in GitHub Desktop.
For Machine Learning and Web Analytics blogpost http://markedmondson.me/intro-to-machine-learning-with-web-analytics-random-forests-and-k-means
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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