Skip to content

Instantly share code, notes, and snippets.

@dettmering dettmering/ml.R
Last active Aug 29, 2015

Embed
What would you like to do?
Machine learning template for R
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
You can’t perform that action at this time.