caret: Interfaces for caret package for data science pipelines.

Description Usage Arguments Details Value Author(s) Examples

Description

Interfaces to caret functions that can be used in a pipeline implemented by magrittr.

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11

Arguments

data

data frame, tibble, list, ...

...

Other arguments passed to the corresponding interfaced function.

Details

Interfaces call their corresponding interfaced function.

Value

Object returned by interfaced function.

Author(s)

Roberto Bertolusso

Examples

  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
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
## Not run: 
library(intubate)
library(magrittr)
library(caret)


## ntbt_avNNet: Neural Networks Using Model Averaging
## Not found example using formula interface, and I am
## completely ignorant to construct one.
data(BloodBrain)
BB <- list(bbbDescr, logBBB)

## Original function to interface
avNNet(bbbDescr, logBBB, size = 5, linout = TRUE, trace = FALSE)

## The interface puts data as first parameter
ntbt_avNNet(BB, bbbDescr, logBBB, size = 5, linout = TRUE, trace = FALSE)

## so it can be used easily in a pipeline.
BB %>%
  ntbt_avNNet(bbbDescr, logBBB, size = 5, linout = TRUE, trace = FALSE)


## ntbt_bagEarth: Bagged Earth

## Original function to interface
bagEarth(Volume ~ ., data = trees)

## The interface puts data as first parameter
ntbt_bagEarth(trees, Volume ~ .)

## so it can be used easily in a pipeline.
trees %>%
  ntbt_bagEarth(Volume ~ .)


## ntbt_bagFDA: Bagged FDA
library(mlbench)
library(earth)
data(Glass)

set.seed(36)
inTrain <- sample(1:dim(Glass)[1], 150)

trainData <- Glass[ inTrain, ]
testData  <- Glass[-inTrain, ]
## Original function to interface
## bagFDA(Type ~ ., trainData)   ## There is an error:
## Error in requireNamespaceQuietStop("mda") : package mda is required
##                               ## even when mda is installed
## For now all of this stays commented.

## The interface puts data as first parameter
## ntbt_bagFDA(trainData, Type ~ .)

## so it can be used easily in a pipeline.
## trainData %>%
##   ntbt_bagFDA(Type ~ .)


## ntbt_calibration: Probability Calibration Plot
data(mdrr)
mdrrDescr <- mdrrDescr[, -nearZeroVar(mdrrDescr)]
mdrrDescr <- mdrrDescr[, -findCorrelation(cor(mdrrDescr), .5)]
inTrain <- createDataPartition(mdrrClass)
trainX <- mdrrDescr[inTrain[[1]], ]
trainY <- mdrrClass[inTrain[[1]]]
testX <- mdrrDescr[-inTrain[[1]], ]
testY <- mdrrClass[-inTrain[[1]]]
library(MASS)
ldaFit <- lda(trainX, trainY)
qdaFit <- qda(trainX, trainY)
testProbs <- data.frame(obs = testY,
lda <- predict(ldaFit, testX)$posterior[,1],
qda <- predict(qdaFit, testX)$posterior[,1])

## Original function to interface
calPlotData <- calibration(obs ~ lda + qda, data = testProbs)
xyplot(calPlotData, auto.key = list(columns = 2))

## The interface puts data as first parameter
calPlotData <- ntbt_calibration(testProbs, obs ~ lda + qda)
xyplot(calPlotData, auto.key = list(columns = 2))

## so it can be used easily in a pipeline.
testProbs %>%
  ntbt_calibration(obs ~ lda + qda) %>%
  xyplot(auto.key = list(columns = 2))


## ntbt_dummyVars
when <- data.frame(time = c("afternoon", "night", "afternoon",
                            "morning", "morning", "morning",
                            "morning", "afternoon", "afternoon"),
                   day = c("Mon", "Mon", "Mon",
                           "Wed", "Wed", "Fri",
                           "Sat", "Sat", "Fri"))

levels(when$time) <- list(morning="morning",
                          afternoon="afternoon",
                          night="night")
levels(when$day) <- list(Mon="Mon", Tue="Tue", Wed="Wed", Thu="Thu",
                         Fri="Fri", Sat="Sat", Sun="Sun")

## Original function to interface
mainEffects <- dummyVars(~ day + time, data = when)
mainEffects
predict(mainEffects, when[1:3,])

## The interface puts data as first parameter
mainEffects <- ntbt_dummyVars(when, ~ day + time)
mainEffects
predict(mainEffects, when[1:3,])

## so it can be used easily in a pipeline.
when %>%
  ntbt_dummyVars(~ day + time) %>%
  predict(when[1:3,])


## ntbt_icr: Independent Component Regression
## Not found example using formula interface, and I am
## completely ignorant to construct one.
data(BloodBrain)
BB <- list(bbbDescr, logBBB)

## Original function to interface
icr(bbbDescr, logBBB, n.comp = 5)

## The interface puts data as first parameter
ntbt_icr(BB, bbbDescr, logBBB, n.comp = 5)

## so it can be used easily in a pipeline.
BB %>%
  ntbt_icr(bbbDescr, logBBB, n.comp = 5)


## ntbt_knn3: k-Nearest Neighbour Classification
## Original function to interface
knn3(Species ~ ., iris)

## The interface puts data as first parameter
ntbt_knn3(iris, Species ~ .)

## so it can be used easily in a pipeline.
iris %>%
  ntbt_knn3(Species ~ .)


## ntbt_lift: Lift Plot
set.seed(1)
simulated <- data.frame(obs = factor(rep(letters[1:2], each = 100)),
perfect = sort(runif(200), decreasing = TRUE),
random = runif(200))
## Original function to interface
lift1 <- lift(obs ~ random, data = simulated)
lift1
xyplot(lift1)

## The interface puts data as first parameter
lift1 <- ntbt_lift(simulated, obs ~ random)
lift1
xyplot(lift1)

## so it can be used easily in a pipeline.
simulated %>%
  ntbt_lift(obs ~ random) %>%
  xyplot()


## ntbt_pcaNNet: Neural Networks with a Principal Component Step
## Not found example using formula interface, and I am
## completely ignorant to construct one.
data(BloodBrain)
BB <- list(bbbDescr, logBBB)

## Original function to interface
pcaNNet(bbbDescr[, 1:10], logBBB, size = 5, linout = TRUE, trace = FALSE)

## The interface puts data as first parameter
ntbt_pcaNNet(BB, bbbDescr[, 1:10], logBBB, size = 5, linout = TRUE, trace = FALSE)

## so it can be used easily in a pipeline.
BB %>%
  ntbt_pcaNNet(bbbDescr[, 1:10], logBBB, size = 5, linout = TRUE, trace = FALSE)


## ntbt_sbf: Selection By Filtering (SBF)
## Not found example using formula interface, and I am
## completely ignorant to construct one.
data(BloodBrain)
BB <- list(bbbDescr, logBBB)

## Be prepared to wait...
## Original function to interface
sbf(bbbDescr, logBBB,
    sbfControl = sbfControl(functions = rfSBF,
                            verbose = FALSE, 
                            method = "cv"))

## The interface puts data as first parameter
ntbt_sbf(BB, bbbDescr, logBBB,
         sbfControl = sbfControl(functions = rfSBF,
                                 verbose = FALSE, 
                                 method = "cv"))

## so it can be used easily in a pipeline.
BB %>%
  ntbt_sbf(bbbDescr, logBBB,
           sbfControl = sbfControl(functions = rfSBF,
                                   verbose = FALSE, 
                                   method = "cv"))


## ntbt_train: Fit Predictive Models over Different Tuning Parameters
library(mlbench)
data(BostonHousing)

## Original function to interface
train(medv ~ . + rm:lstat, data = BostonHousing, method = "lm")

## The interface puts data as first parameter
ntbt_train(BostonHousing, medv ~ . + rm:lstat, method = "lm")

## so it can be used easily in a pipeline.
BostonHousing %>%
  ntbt_train(medv ~ . + rm:lstat, method = "lm")

## End(Not run)

intubate documentation built on May 2, 2019, 2:46 p.m.