-
Notifications
You must be signed in to change notification settings - Fork 636
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
18 changed files
with
534 additions
and
496 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,46 +1,48 @@ | ||
# Sample .travis.yml for R projects from https://github.com/craigcitro/r-travis | ||
|
||
language: c | ||
language: r | ||
warnings_are_errors: false | ||
sudo: required | ||
|
||
env: | ||
global: | ||
- WARNINGS_ARE_ERRORS=1 | ||
- R_BUILD_ARGS=" " | ||
- R_CHECK_ARGS="--as-cran" | ||
- BOOTSTRAP_LATEX="1" | ||
- CRAN: http://cran.rstudio.com | ||
- R_BUILD_ARGS="--no-build-vignettes --no-manual" | ||
- R_CHECK_ARGS="--no-build-vignettes --no-manual --as-cran" | ||
matrix: | ||
- NOT_CRAN="true" | ||
- NOT_CRAN="false" | ||
|
||
before_install: | ||
- cd pkg/caret | ||
- curl -OL http://raw.github.com/craigcitro/r-travis/master/scripts/travis-tool.sh | ||
- chmod 755 ./travis-tool.sh | ||
- ./travis-tool.sh bootstrap | ||
|
||
install: | ||
- ./travis-tool.sh install_deps | ||
- sudo add-apt-repository -y ppa:texlive-backports/ppa | ||
- sudo apt-get -qq update | ||
- ./travis-tool.sh aptget_install texlive-base | ||
- ./travis-tool.sh aptget_install biblatex | ||
- ./travis-tool.sh aptget_install texlive-latex-base | ||
- ./travis-tool.sh aptget_install texlive-latex-recommended | ||
- ./travis-tool.sh aptget_install texlive-latex-extra | ||
- ./travis-tool.sh aptget_install texlive-fonts-recommended | ||
- ./travis-tool.sh aptget_install texlive-fonts-extra | ||
- ./travis-tool.sh aptget_install texlive-science | ||
- ./travis-tool.sh github_package jimhester/covr | ||
|
||
script: ./travis-tool.sh run_tests | ||
|
||
on_failure: | ||
- ./travis-tool.sh dump_logs | ||
|
||
after_success: | ||
- Rscript -e 'library(covr);coveralls()' | ||
apt_packages: | ||
- texlive-base | ||
- biblatex | ||
- texlive-latex-base | ||
- texlive-latex-recommended | ||
- texlive-latex-extra | ||
- texlive-fonts-recommended | ||
- texlive-fonts-extra | ||
- texlive-science | ||
|
||
r_packages: | ||
- arm | ||
- glmnet | ||
- rpart | ||
- C50 | ||
- ipred | ||
- plyr | ||
- earth | ||
- kknn | ||
|
||
r_github_packages: | ||
- jimhester/covr | ||
|
||
notifications: | ||
email: | ||
on_success: change | ||
on_failure: change | ||
|
||
after_success: | ||
- Rscript -e 'library(covr);coveralls()' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
library(caret) | ||
context('Test Data Splitting Functions') | ||
|
||
test_that('createTimeSlices', { | ||
set.seed(1) | ||
y <- 1:10 | ||
|
||
s1 <- createTimeSlices(y, initialWindow=5, horizon=1, fixedWindow=TRUE) | ||
expect_equal(length(s1$train), 5) | ||
expect_equal(length(s1$test), 5) | ||
expect_equal(s1$train$Training1, 1:5) | ||
expect_equal(s1$train$Training2, 2:6) | ||
expect_equal(s1$train$Training3, 3:7) | ||
expect_equal(s1$train$Training4, 4:8) | ||
expect_equal(s1$train$Training5, 5:9) | ||
expect_equal(s1$test$Testing1, 6) | ||
expect_equal(s1$test$Testing2, 7) | ||
expect_equal(s1$test$Testing3, 8) | ||
expect_equal(s1$test$Testing4, 9) | ||
expect_equal(s1$test$Testing5, 10) | ||
|
||
s2 <- createTimeSlices(y, initialWindow=5, horizon=1, fixedWindow=FALSE) | ||
expect_equal(length(s2$train), 5) | ||
expect_equal(length(s2$test), 5) | ||
expect_equal(s2$train$Training1, 1:5) | ||
expect_equal(s2$train$Training2, 1:6) | ||
expect_equal(s2$train$Training3, 1:7) | ||
expect_equal(s2$train$Training4, 1:8) | ||
expect_equal(s2$train$Training5, 1:9) | ||
expect_equal(s2$test$Testing1, 6) | ||
expect_equal(s2$test$Testing2, 7) | ||
expect_equal(s2$test$Testing3, 8) | ||
expect_equal(s2$test$Testing4, 9) | ||
expect_equal(s2$test$Testing5, 10) | ||
|
||
s3 <- createTimeSlices(y, initialWindow=5, horizon=5, fixedWindow=TRUE) | ||
expect_equal(length(s3$train), 1) | ||
expect_equal(length(s3$test), 1) | ||
expect_equal(s3$train$Training1, 1:5) | ||
expect_equal(s3$test$Testing1, 6:10) | ||
|
||
s4 <- createTimeSlices(y, initialWindow=5, horizon=5, fixedWindow=FALSE) | ||
expect_equal(length(s3$train), 1) | ||
expect_equal(length(s3$test), 1) | ||
expect_equal(s3$train$Training1, 1:5) | ||
expect_equal(s3$test$Testing1, 6:10) | ||
|
||
expect_identical(s3, s4) | ||
}) |
54 changes: 20 additions & 34 deletions
54
pkg/caret/tests/testthat/trim.R → pkg/caret/tests/testthat/test_trim.R
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,69 +1,55 @@ | ||
context('Test model object trimming') | ||
context('Base model trimming works') | ||
|
||
library(rpart) | ||
library(ipred) | ||
|
||
################################################################### | ||
## rpart tests functions | ||
## rpart tests | ||
|
||
check_rpart_reg <- function() { | ||
test_that("trimmed rpart regression produces identical predicted values", { | ||
skip_on_cran() | ||
set.seed(1) | ||
train_dat <- SLC14_1(100) | ||
train_dat$factor_var <- factor(sample(letters[1:2], nrow(train_dat), replace = TRUE)) | ||
test_dat <- SLC14_1(1000) | ||
test_dat$factor_var <- factor(sample(letters[1:2], nrow(test_dat), replace = TRUE)) | ||
|
||
library(rpart) | ||
rpart_full <- rpart(y ~ ., data = train_dat) | ||
rpart_trim <- caret:::trim(rpart_full) | ||
predict(rpart_full, test_dat) - predict(rpart_trim, test_dat) | ||
} | ||
rpart_trim <- getModelInfo('rpart', regex=FALSE)[[1]]$trim(rpart_full) | ||
expect_identical(predict(rpart_full, test_dat), predict(rpart_trim, test_dat)) | ||
expect_less_than(object.size(rpart_trim), object.size(rpart_full)) | ||
}) | ||
|
||
check_rpart_class <- function() { | ||
test_that("trimmed rpart classification produces identical predicted values", { | ||
skip_on_cran() | ||
set.seed(1) | ||
train_dat <- twoClassSim(100) | ||
train_dat$factor_var <- factor(sample(letters[1:2], nrow(train_dat), replace = TRUE)) | ||
test_dat <- twoClassSim(1000) | ||
test_dat$factor_var <- factor(sample(letters[1:2], nrow(test_dat), replace = TRUE)) | ||
|
||
library(rpart) | ||
rpart_full <- rpart(Class ~ ., data = train_dat) | ||
rpart_trim <- caret:::trim(rpart_full) | ||
predict(rpart_full, test_dat)[, "Class1"] - predict(rpart_trim, test_dat)[, "Class1"] | ||
} | ||
rpart_trim <- getModelInfo('rpart', regex=FALSE)[[1]]$trim(rpart_full) | ||
expect_identical(predict(rpart_full, test_dat)[, "Class1"], predict(rpart_trim, test_dat)[, "Class1"]) | ||
expect_less_than(object.size(rpart_trim), object.size(rpart_full)) | ||
}) | ||
|
||
################################################################### | ||
## bagging tests functions | ||
## bagging tests | ||
|
||
check_bag_reg <- function() { | ||
test_that("trimmed bagging regression produces identical predicted values", { | ||
skip_on_cran() | ||
set.seed(1) | ||
train_dat <- SLC14_1(100) | ||
train_dat$factor_var <- factor(sample(letters[1:2], nrow(train_dat), replace = TRUE)) | ||
test_dat <- SLC14_1(1000) | ||
test_dat$factor_var <- factor(sample(letters[1:2], nrow(test_dat), replace = TRUE)) | ||
|
||
library(rpart) | ||
bag_full <- bagging(y ~ ., data = train_dat) | ||
bag_trim <- caret:::trim(bag_full) | ||
predict(bag_full, test_dat) - predict(bag_trim, test_dat) | ||
} | ||
|
||
################################################################### | ||
## Tests | ||
|
||
test_that("trimmed rpart regression produces identical predicted values", { | ||
expect_that(sum(check_rpart_reg()), equals(0)) | ||
}) | ||
|
||
test_that("trimmed rpart classification produces identical predicted values", { | ||
expect_that(sum(check_rpart_class()), equals(0)) | ||
bag_trim <- getModelInfo('treebag', regex=FALSE)[[1]]$trim(bag_full) | ||
expect_identical(predict(bag_full, test_dat), predict(bag_trim, test_dat)) | ||
expect_less_than(object.size(bag_trim), object.size(bag_full)) | ||
}) | ||
|
||
test_that("trimmed bagging regression produces identical predicted values", { | ||
expect_that(sum(check_bag_reg()), equals(0)) | ||
}) | ||
|
||
|
Oops, something went wrong.