= R caret = '''caret''' ('''''C''lassification ''A''nd ''RE''gression ''T''raining''') is a library of functions for model training. <> ---- == Installation == {{{ install.packages('caret') }}} ---- == Usage == The '''`createDataPartition`''' function randomly partitions a vector of outcomes. {{{ data(mtcars) parts = createDataPartition(mtcars$mpg, p = .8) train = mtcars[parts, ] test = mtcars[-parts, ] }}} `createDataPartition` returns a list object. To instead return a matrix, pass `list = FALSE` as an option. The '''`confusionMatrix`''' function prepares the confusion matrix for a prediction, such as that from an [[R/XGBoost|XGBoost]] model. {{{ my.data <- xgb.DMatrix(data = df[,predictors], label=df$outcome) my.model <- xgboost(data = my.data, objective = "binary:logistic", ...) pred <- predict(my.model, my.data) pred <- ifelse(pred > 0.5, 1, 0) confusionMatrix(as.factor(pred), as.factor(df$outcome)) }}} ---- CategoryRicottone