-
-
Save dettmering/0c81684b271edefebebb to your computer and use it in GitHub Desktop.
Machine learning template for R
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(caret) | |
library(doMC) | |
registerDoMC(cores = 4) # use multiple cores | |
set.seed(1234) | |
col.of.interest <- c( | |
'response', 'A', 'B', 'C' | |
) | |
inTraining <- createDataPartition(df$response, p = 0.75, list = FALSE) | |
tr <- df[inTraining, col.of.interest] | |
te <- df[-inTraining, col.of.interest] | |
tr$response <- as.factor(tr$response) | |
te$response <- as.factor(te$response) | |
fitControl <- trainControl(method = "repeatedcv", number = 10, repeats = 10) | |
fit <- train(response ~ ., data = tr, method = "rf", trainControl = fitControl) | |
prd <- predict(fit, te) | |
confusionMatrix(prd, te$response) | |
varImp(fit, scale = FALSE) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment