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
|
library(caret)
test_that('train classification', {
skip_on_cran()
set.seed(1)
tr_dat <- twoClassSim(200)
te_dat <- twoClassSim(200)
set.seed(2)
class_trim <- train(Class ~ ., data = tr_dat,
method = "rpart",
tuneGrid = data.frame(cp = 0.22),
preProc = c("center", "bagImpute"),
trControl = trainControl(method = "none",
classProbs = TRUE,
trim = TRUE))
class_trim <- caret:::trim.train(class_trim)
set.seed(2)
class_notrim <- train(Class ~ ., data = tr_dat,
method = "rpart",
tuneGrid = data.frame(cp = 0.22),
preProc = c("center", "bagImpute"),
trControl = trainControl(method = "none",
classProbs = TRUE,
trim = FALSE))
expect_equal(predict(class_trim, te_dat),
predict(class_notrim, te_dat))
expect_equal(predict(class_trim, te_dat, type = "prob"),
predict(class_notrim, te_dat, type = "prob"))
expect_less_than(object.size(class_trim)-object.size(class_notrim), 0)
})
test_that('train regression', {
skip_on_cran()
set.seed(1)
tr_dat <- SLC14_1(200)
te_dat <- SLC14_1(200)
set.seed(2)
reg_trim <- train(y ~ ., data = tr_dat,
method = "rpart",
tuneGrid = data.frame(cp = 0.12),
trControl = trainControl(method = "none",
trim = TRUE))
reg_trim <- caret:::trim.train(reg_trim)
set.seed(2)
reg_notrim <- train(y ~ ., data = tr_dat,
method = "rpart",
tuneGrid = data.frame(cp = 0.12),
trControl = trainControl(method = "none",
trim = FALSE))
expect_equal(predict(reg_trim, te_dat),
predict(reg_notrim, te_dat))
expect_less_than(object.size(reg_trim)-object.size(reg_notrim), 0)
})
test_that('train/earth classification', {
skip_on_cran()
set.seed(1)
tr_dat <- twoClassSim(200)
te_dat <- twoClassSim(200)
set.seed(2)
class_trim <- train(Class ~ ., data = tr_dat,
method = "earth",
tuneGrid = data.frame(nprune = 3, degree = 1),
trControl = trainControl(method = "none",
classProbs = TRUE,
trim = TRUE))
class_trim <- caret:::trim.train(class_trim)
set.seed(2)
class_notrim <- train(Class ~ ., data = tr_dat,
method = "earth",
tuneGrid = data.frame(nprune = 3, degree = 1),
trControl = trainControl(method = "none",
classProbs = TRUE,
trim = FALSE))
expect_equal(predict(class_trim, te_dat),
predict(class_notrim, te_dat))
expect_equal(predict(class_trim, te_dat, type = "prob"),
predict(class_notrim, te_dat, type = "prob"))
expect_less_than(object.size(class_trim)-object.size(class_notrim), 0)
})
test_that('train/earth regression', {
skip_on_cran()
set.seed(1)
tr_dat <- SLC14_1(200)
te_dat <- SLC14_1(200)
set.seed(2)
reg_trim <- train(y ~ ., data = tr_dat,
method = "earth",
tuneGrid = data.frame(nprune = 3, degree = 1),
trControl = trainControl(method = "none",
trim = TRUE))
set.seed(2)
reg_notrim <- train(y ~ ., data = tr_dat,
method = "earth",
tuneGrid = data.frame(nprune = 3, degree = 1),
trControl = trainControl(method = "none",
trim = FALSE))
expect_equal(predict(reg_trim, te_dat),
predict(reg_notrim, te_dat))
expect_less_than(object.size(reg_trim)-object.size(reg_notrim), 0)
})
|