/usr/lib/R/site-library/caret/doc/caret.R is in r-cran-caret 6.0-78+dfsg1-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 | ### R code from vignette source 'caret.Rnw'
###################################################
### code chunk number 1: loadLibs
###################################################
library(MASS)
library(caret)
library(mlbench)
data(Sonar)
library(pROC)
library(pls)
options(useFancyQuotes = FALSE)
getInfo <- function(what = "Suggests")
{
text <- packageDescription("caret")[what][[1]]
text <- gsub("\n", ", ", text, fixed = TRUE)
text <- gsub(">=", "$\\\\ge$", text, fixed = TRUE)
eachPkg <- strsplit(text, ", ", fixed = TRUE)[[1]]
eachPkg <- gsub(",", "", eachPkg, fixed = TRUE)
#out <- paste("\\\\pkg{", eachPkg[order(tolower(eachPkg))], "}", sep = "")
#paste(out, collapse = ", ")
length(eachPkg)
}
###################################################
### code chunk number 2: install (eval = FALSE)
###################################################
## install.packages("caret", dependencies = c("Depends", "Suggests"))
###################################################
### code chunk number 3: SonarSplit
###################################################
library(caret)
library(mlbench)
data(Sonar)
set.seed(107)
inTrain <- createDataPartition(y = Sonar$Class,
## the outcome data are needed
p = .75,
## The percentage of data in the
## training set
list = FALSE)
## The format of the results
## The output is a set of integers for the rows of Sonar
## that belong in the training set.
str(inTrain)
###################################################
### code chunk number 4: SonarDatasets
###################################################
training <- Sonar[ inTrain,]
testing <- Sonar[-inTrain,]
nrow(training)
nrow(testing)
###################################################
### code chunk number 5: plsTune1 (eval = FALSE)
###################################################
## plsFit <- train(Class ~ .,
## data = training,
## method = "pls",
## ## Center and scale the predictors for the training
## ## set and all future samples.
## preProc = c("center", "scale"))
###################################################
### code chunk number 6: plsFit
###################################################
ctrl <- trainControl(method = "repeatedcv",
repeats = 3,
classProbs = TRUE,
summaryFunction = twoClassSummary)
set.seed(123)
plsFit <- train(Class ~ .,
data = training,
method = "pls",
tuneLength = 15,
trControl = ctrl,
metric = "ROC",
preProc = c("center", "scale"))
###################################################
### code chunk number 7: plsPrint
###################################################
plsFit
###################################################
### code chunk number 8: baPlot
###################################################
trellis.par.set(caretTheme())
print(plot(plsFit))
###################################################
### code chunk number 9: plsPred
###################################################
plsClasses <- predict(plsFit, newdata = testing)
str(plsClasses)
plsProbs <- predict(plsFit, newdata = testing, type = "prob")
head(plsProbs)
###################################################
### code chunk number 10: plsCM
###################################################
confusionMatrix(data = plsClasses, testing$Class)
###################################################
### code chunk number 11: rdaFit
###################################################
## To illustrate, a custom grid is used
rdaGrid = data.frame(gamma = (0:4)/4, lambda = 3/4)
set.seed(123)
rdaFit <- train(Class ~ .,
data = training,
method = "rda",
tuneGrid = rdaGrid,
trControl = ctrl,
metric = "ROC")
rdaFit
rdaClasses <- predict(rdaFit, newdata = testing)
confusionMatrix(rdaClasses, testing$Class)
###################################################
### code chunk number 12: rs
###################################################
resamps <- resamples(list(pls = plsFit, rda = rdaFit))
summary(resamps)
###################################################
### code chunk number 13: diffs
###################################################
diffs <- diff(resamps)
summary(diffs)
###################################################
### code chunk number 14: plsPlot
###################################################
plotTheme <- caretTheme()
plotTheme$plot.symbol$col <- rgb(.2, .2, .2, .5)
plotTheme$plot.symbol$pch <- 16
trellis.par.set(plotTheme)
print(xyplot(resamps, what = "BlandAltman"))
|