Package ‘caret’ October12,2022 Title ClassificationandRegressionTraining Version 6.0-93 Description Miscfunctionsfortrainingandplottingclassificationand regressionmodels. License GPL(>=2) URL https://github.com/topepo/caret/ BugReports https://github.com/topepo/caret/issues Depends ggplot2,lattice(>=0.20),R(>=3.2.0) Imports e1071,foreach,grDevices,methods,ModelMetrics(>=1.2.2.2), nlme,plyr,pROC,recipes(>=0.1.10),reshape2,stats,stats4, utils,withr(>=2.0.0) Suggests BradleyTerry2,covr,Cubist,dplyr,earth(>=2.2-3), ellipse,fastICA,gam(>=1.15),ipred,kernlab,klaR,knitr, MASS,Matrix,mda,mgcv,mlbench,MLmetrics,nnet,pamr,party (>=0.9-99992),pls,proxy,randomForest,RANN,rmarkdown, rpart,spls,subselect,superpc,testthat(>=0.9.1),themis (>=0.1.3) VignetteBuilder knitr Encoding UTF-8 RoxygenNote 7.2.0 NeedsCompilation yes Author MaxKuhn[aut,cre](<https://orcid.org/0000-0003-2402-136X>), JedWing[ctb], SteveWeston[ctb], AndreWilliams[ctb], ChrisKeefer[ctb], AllanEngelhardt[ctb], TonyCooper[ctb], ZacharyMayer[ctb], BrentonKenkel[ctb], RCoreTeam[ctb], 1 2 Rtopicsdocumented: MichaelBenesty[ctb], ReynaldLescarbeau[ctb], AndrewZiem[ctb], LucaScrucca[ctb], YuanTang[ctb], CanCandan[ctb], TylerHunt[ctb] Maintainer MaxKuhn<[email protected]> Repository CRAN Date/Publication 2022-08-0910:00:02UTC R topics documented: as.matrix.confusionMatrix . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4 avNNet . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5 bag. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8 bagEarth . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11 bagFDA . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13 BloodBrain . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15 BoxCoxTrans . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15 calibration . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17 caretSBF . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20 cars . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21 classDist . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 22 confusionMatrix. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24 confusionMatrix.train . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 27 cox2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 29 createDataPartition . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 30 defaultSummary. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 32 densityplot.rfe . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 35 dhfr . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 36 diff.resamples . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 37 dotPlot . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 39 dotplot.diff.resamples . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 40 downSample. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 41 dummyVars . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 42 extractPrediction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 46 featurePlot . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 48 filterVarImp . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 49 findCorrelation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 51 findLinearCombos . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 52 format.bagEarth . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 54 gafs.default . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 55 gafsControl . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 58 gafs_initial . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 61 GermanCredit . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 63 getSamplingInfo . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 64 Rtopicsdocumented: 3 ggplot.rfe . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 65 ggplot.train . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 66 histogram.train . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 69 icr.formula. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 70 index2vec . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 72 knn3 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 73 knnreg . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 74 learning_curve_dat . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 76 lift . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 78 maxDissim . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 81 mdrr . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 83 modelLookup . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 84 nearZeroVar . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 86 negPredValue . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 88 nullModel . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 92 oil . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 93 oneSE . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 94 panel.lift2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 96 panel.needle . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 98 pcaNNet . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 99 pickSizeBest . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 101 plot.gafs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 103 plot.varImp.train . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 105 plotClassProbs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 106 plotObsVsPred . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 108 plsda . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 109 pottery . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 112 prcomp.resamples . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 112 predict.bagEarth . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 114 predict.gafs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 116 predict.knn3 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 117 predict.knnreg . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 118 predictors . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 118 preProcess . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 119 print.confusionMatrix . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 123 print.train . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 124 recall . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 125 resampleHist . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 128 resamples . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 129 resampleSummary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 132 rfe . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 133 rfeControl . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 137 Sacramento . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 141 safs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 141 safs_initial . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 144 sbf . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 147 sbfControl . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 150 scat . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 153 4 as.matrix.confusionMatrix segmentationData . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 153 SLC14_1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 154 spatialSign. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 158 summary.bagEarth . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 159 tecator . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 160 thresholder . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 161 train . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 163 trainControl . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 169 train_model_list . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 174 update.safs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 206 update.train . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 207 varImp . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 208 varImp.gafs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 213 var_seq . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 214 xyplot.resamples . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 215 Index 219 as.matrix.confusionMatrix Confusionmatrixasatable Description ConversionfunctionsforclassconfusionMatrix Usage ## S3 method for class 'confusionMatrix' as.matrix(x, what = "xtabs", ...) Arguments x anobjectofclassconfusionMatrix what datatoconverttomatrix. Either"xtabs","overall"or"classes" ... notcurrentlyused Details Foras.table,thecross-tabulationsaresaved. Foras.matrix,thethreeobjecttypesaresavedin matrixformat. Value Amatrixortable Author(s) MaxKuhn avNNet 5 Examples ################### ## 2 class example lvs <- c("normal", "abnormal") truth <- factor(rep(lvs, times = c(86, 258)), levels = rev(lvs)) pred <- factor( c( rep(lvs, times = c(54, 32)), rep(lvs, times = c(27, 231))), levels = rev(lvs)) xtab <- table(pred, truth) results <- confusionMatrix(xtab) as.table(results) as.matrix(results) as.matrix(results, what = "overall") as.matrix(results, what = "classes") ################### ## 3 class example xtab <- confusionMatrix(iris$Species, sample(iris$Species)) as.matrix(xtab) avNNet NeuralNetworksUsingModelAveraging Description Aggregateseveralneuralnetworkmodels Usage avNNet(x, ...) ## S3 method for class 'formula' avNNet( formula, data, weights, ..., repeats = 5, bag = FALSE, allowParallel = TRUE, seeds = sample.int(1e+05, repeats), 6 avNNet subset, na.action, contrasts = NULL ) ## Default S3 method: avNNet( x, y, repeats = 5, bag = FALSE, allowParallel = TRUE, seeds = sample.int(1e+05, repeats), ... ) ## S3 method for class 'avNNet' print(x, ...) ## S3 method for class 'avNNet' predict(object, newdata, type = c("raw", "class", "prob"), ...) Arguments x matrixordataframeofxvaluesforexamples. ... argumentspassedtonnet formula Aformulaoftheformclass~x1+x2+... data Data frame from which variables specified in formula are preferentially to be taken. weights (case)weightsforeachexample-ifmissingdefaultsto1. repeats thenumberofneuralnetworkswithdifferentrandomnumberseeds bag alogicalforbaggingforeachrepeat allowParallel ifaparallelbackendisloadedandavailable,shouldthefunctionuseit? seeds random number seeds that can be set prior to bagging (if done) and network creation. Thishelpsmaintainreproducibilitywhenmodelsareruninparallel. subset Anindexvectorspecifyingthecasestobeusedinthetrainingsample. (NOTE: Ifgiven,thisargumentmustbenamed.) na.action AfunctiontospecifytheactiontobetakenifNAsarefound. Thedefaultaction isfortheproceduretofail. Analternativeisna.omit,whichleadstorejection of cases with missing values on any required variable. (NOTE: If given, this argumentmustbenamed.) contrasts alistofcontraststobeusedforsomeorallofthefactorsappearingasvariables inthemodelformula. y matrixordataframeoftargetvaluesforexamples. object anobjectofclassavNNetasreturnedbyavNNet. avNNet 7 newdata matrixordataframeoftestexamples. Avectorisconsideredtobearowvector comprisingasinglecase. type Typeofoutput,either: rawfortherawoutputs,codeforthepredictedclassor probfortheclassprobabilities. Details FollowingRipley(1996),thesameneuralnetworkmodelisfitusingdifferentrandomnumberseeds. Alltheresultingmodelsareusedforprediction. Forregression,theoutputfromeachnetworkare averaged.Forclassification,themodelscoresarefirstaveraged,thentranslatedtopredictedclasses. Baggingcanalsobeusedtocreatethemodels. Ifaparallelbackendisregistered,theforeachpackageisusedtotrainthenetworksinparallel. Value ForavNNet,anobjectof"avNNet"or"avNNet.formula". Itemsofinterestin#’theoutputare: model alistofthemodelsgeneratedfromnnet repeats anechoofthemodelinput names ifanypredictorshadonlyonedistinctvalue,thisisacharacterstringofthe#’ remainingcolumns. OtherwiseavalueofNULL Author(s) TheseareheavilybasedonthennetcodefromBrianRipley. References Ripley,B.D.(1996)PatternRecognitionandNeuralNetworks. Cambridge. SeeAlso nnet,preProcess Examples data(BloodBrain) ## Not run: modelFit <- avNNet(bbbDescr, logBBB, size = 5, linout = TRUE, trace = FALSE) modelFit predict(modelFit, bbbDescr) ## End(Not run) 8 bag bag AGeneralFrameworkForBagging Description bag provides a framework for bagging classification or regression models. The user can provide theirownfunctionsformodelbuilding, predictionandaggregationofpredictions(seeDetailsbe- low). Usage bag(x, ...) bagControl( fit = NULL, predict = NULL, aggregate = NULL, downSample = FALSE, oob = TRUE, allowParallel = TRUE ) ## Default S3 method: bag(x, y, B = 10, vars = ncol(x), bagControl = NULL, ...) ## S3 method for class 'bag' predict(object, newdata = NULL, ...) ## S3 method for class 'bag' print(x, ...) ## S3 method for class 'bag' summary(object, ...) ## S3 method for class 'summary.bag' print(x, digits = max(3, getOption("digits") - 3), ...) ldaBag plsBag nbBag ctreeBag svmBag bag 9 nnetBag Arguments x amatrixordataframeofpredictors ... argumentstopasstothemodelfunction fit a function that has arguments x, y and ... and produces a model object #’ that can later be used for prediction. Example functions are found in ldaBag, plsBag,#’nbBag,svmBagandnnetBag. predict a function that generates predictions for each sub-model. The function should have #’ arguments object and x. The output of the function can be any type of object (see the #’ example below where posterior probabilities are gener- ated. Example functions are found in ldaBag#’ , plsBag, nbBag, svmBag and nnetBag.) aggregate afunctionwithargumentsxandtype. Thefunctionthattakestheoutput#’of thepredictfunctionandreducesthebaggedpredictionstoasingleprediction per sample. #’ the type argument can be used to switch between predicting classesorclassprobabilitiesfor#’classificationmodels. Examplefunctionsare foundinldaBag,plsBag,nbBag,#’svmBagandnnetBag. downSample logical: forclassification,shouldthedatasetberandomlysampledsothateach #’classhasthesamenumberofsamplesasthesmallestclass? oob logical: shouldout-of-bagstatisticsbecomputedandthepredictionsretained? allowParallel aparallelbackendisloadedandavailable,shouldthefunctionuseit? y avectorofoutcomes B thenumberofbootstrapsamplestotrainover. vars aninteger. IfthisargumentisnotNULL,arandomsampleofsizevarsistaken ofthepredictorsineachbaggingiteration. IfNULL,allpredictorsareused. bagControl alistofoptions. object anobjectofclassbag. newdata amatrixordataframeofsamplesforprediction. Notethatthisargumentmust haveanon-nullvalue digits minimalnumberofsignificantdigits. Format Anobjectofclasslistoflength3. Anobjectofclasslistoflength3. Anobjectofclasslistoflength3. Anobjectofclasslistoflength3. Anobjectofclasslistoflength3. Anobjectofclasslistoflength3. 10 bag Details Thefunctionisbasicallyaframeworkwhereuserscanpluginanymodelintoassesstheeffectof bagging. ExamplesfunctionscanbefoundinldaBag,plsBag,nbBag,svmBagandnnetBag. Each haselementsfit,predandaggregate. Onenote: whenvarsisnotNULL,thesub-settingoccurspriortothefitand#’predictfunctions arecalled. Inthisway,theuserprobablydoesnotneedtoaccountforthe#’changeinpredictorsin theirfunctions. When using bag with train, classification models should use type="prob" #’ inside of the predictfunctionsothatpredict.train(object,newdata,type="prob")will#’work. Ifaparallelbackendisregistered,theforeachpackageisusedtotrainthemodelsinparallel. Value bagproducesanobjectofclassbagwithelements fits a list with two sub-objects: the fit object has the actual model fit for that #’ baggedsamplesandthevarsobjectiseitherNULLoravectorofintegerscorre- spondingtowhichpredictorsweresampledforthatmodel control amirroroftheargumentspassedintobagControl call thecall B thenumberofbaggingiterations dims thedimensionsofthetrainingset Author(s) MaxKuhn Examples ## A simple example of bagging conditional inference regression trees: data(BloodBrain) ## treebag <- bag(bbbDescr, logBBB, B = 10, ## bagControl = bagControl(fit = ctreeBag$fit, ## predict = ctreeBag$pred, ## aggregate = ctreeBag$aggregate)) ## An example of pooling posterior probabilities to generate class predictions data(mdrr) ## remove some zero variance predictors and linear dependencies mdrrDescr <- mdrrDescr[, -nearZeroVar(mdrrDescr)] mdrrDescr <- mdrrDescr[, -findCorrelation(cor(mdrrDescr), .95)] ## basicLDA <- train(mdrrDescr, mdrrClass, "lda")
Description: