From 4a8b83100a4efee2d6ab8c08fd3e82d0472d234b Mon Sep 17 00:00:00 2001 From: topepo Date: Wed, 27 Feb 2019 15:38:26 -0500 Subject: [PATCH 01/34] changes to #115 --- .gitignore | 2 + NEWS.md | 2 + R/fit_helpers.R | 42 ++++++++++++------- tests/testthat/test_boost_tree_C50.R | 16 +++++-- tests/testthat/test_linear_reg_stan.R | 12 +++--- tests/testthat/test_logistic_reg.R | 31 +++++++------- tests/testthat/test_logistic_reg_glmnet.R | 14 +++---- tests/testthat/test_logistic_reg_stan.R | 6 ++- tests/testthat/test_multinom_reg_glmnet.R | 14 +++---- tests/testthat/test_nearest_neighbor_kknn.R | 7 ++-- tests/testthat/test_predict_formats.R | 19 +++++++++ .../testthat/test_rand_forest_randomForest.R | 13 +++--- tests/testthat/test_rand_forest_ranger.R | 13 +++--- 13 files changed, 119 insertions(+), 72 deletions(-) diff --git a/.gitignore b/.gitignore index 058237471..99bec7b71 100644 --- a/.gitignore +++ b/.gitignore @@ -5,3 +5,5 @@ tests/testthat/derby.log tests/testthat/logs/ *.history +derby.log +logs/* diff --git a/NEWS.md b/NEWS.md index 775ee3b28..53b2a260c 100644 --- a/NEWS.md +++ b/NEWS.md @@ -13,6 +13,8 @@ that are actually varying). * `fit_control()` not returns an S3 method. +* For classification models, an error occurs if the outcome data are not encoded as factors (#115). + ## Bug Fixes * `varying_args()` now uses the version from the `generics` package. This means diff --git a/R/fit_helpers.R b/R/fit_helpers.R index 23f8cb9e0..74f614ede 100644 --- a/R/fit_helpers.R +++ b/R/fit_helpers.R @@ -6,13 +6,13 @@ #' @importFrom stats model.frame model.response terms as.formula model.matrix form_form <- function(object, control, env, ...) { - opts <- quos(...) - if (object$mode != "regression") { - y_levels <- levels_from_formula( # prob rewrite this as simple subset/levels - env$formula, - env$data - ) + if (object$mode == "classification") { + # prob rewrite this as simple subset/levels + y_levels <- levels_from_formula(env$formula, env$data) + if (!inherits(env$data, "tbl_spark") && is.null(y_levels)) + stop("For classification models, the outcome should be a factor.", + call. = FALSE) } else { y_levels <- NULL } @@ -20,7 +20,7 @@ form_form <- object <- check_mode(object, y_levels) # if descriptors are needed, update descr_env with the calculated values - if(requires_descrs(object)) { + if (requires_descrs(object)) { data_stats <- get_descr_form(env$formula, env$data) scoped_descrs(data_stats) } @@ -71,8 +71,14 @@ xy_xy <- function(object, env, control, target = "none", ...) { object <- check_mode(object, levels(env$y)) + if (object$mode == "classification") { + if (is.null(levels(env$y))) + stop("For classification models, the outcome should be a factor.", + call. = FALSE) + } + # if descriptors are needed, update descr_env with the calculated values - if(requires_descrs(object)) { + if (requires_descrs(object)) { data_stats <- get_descr_form(env$formula, env$data) scoped_descrs(data_stats) } @@ -125,13 +131,12 @@ form_xy <- function(object, control, env, env$x <- data_obj$x env$y <- data_obj$y - res <- list( - lvl = levels_from_formula( - env$formula, - env$data - ), - spec = object - ) + res <- list(lvl = levels_from_formula(env$formula, env$data), spec = object) + if (object$mode == "classification") { + if (is.null(res$lvl)) + stop("For classification models, the outcome should be a factor.", + call. = FALSE) + } res <- xy_xy( object = object, @@ -148,6 +153,13 @@ form_xy <- function(object, control, env, } xy_form <- function(object, env, control, ...) { + + if (object$mode == "classification") { + if (is.null(levels(env$y))) + stop("For classification models, the outcome should be a factor.", + call. = FALSE) + } + data_obj <- convert_xy_to_form_fit( x = env$x, diff --git a/tests/testthat/test_boost_tree_C50.R b/tests/testthat/test_boost_tree_C50.R index 81e30fd62..e712c5ab1 100644 --- a/tests/testthat/test_boost_tree_C50.R +++ b/tests/testthat/test_boost_tree_C50.R @@ -1,6 +1,7 @@ library(testthat) library(parsnip) library(tibble) +library(dplyr) # ------------------------------------------------------------------------------ @@ -8,6 +9,9 @@ context("boosted tree execution with C5.0") data("lending_club") lending_club <- head(lending_club, 200) +lending_club_fail <- + lending_club %>% + mutate(bad = Inf, miss = NA) num_pred <- c("funded_amnt", "annual_inc", "num_il_tl") lc_basic <- boost_tree(mode = "classification") %>% @@ -41,6 +45,8 @@ test_that('C5.0 execution', { ), regexp = NA ) + + # outcome is not a factor: expect_error( res <- fit( lc_basic, @@ -51,19 +57,21 @@ test_that('C5.0 execution', { ) ) + # Model fails C5.0_form_catch <- fit( lc_basic, - funded_amnt ~ term, - data = lending_club, + Class ~ miss, + data = lending_club_fail, control = caught_ctrl ) expect_true(inherits(C5.0_form_catch$fit, "try-error")) + # Model fails C5.0_xy_catch <- fit_xy( lc_basic, control = caught_ctrl, - x = lending_club[, num_pred], - y = lending_club$total_bal_il + x = lending_club_fail[, "miss"], + y = lending_club_fail$Class ) expect_true(inherits(C5.0_xy_catch$fit, "try-error")) }) diff --git a/tests/testthat/test_linear_reg_stan.R b/tests/testthat/test_linear_reg_stan.R index 4891e65e1..08555e0df 100644 --- a/tests/testthat/test_linear_reg_stan.R +++ b/tests/testthat/test_linear_reg_stan.R @@ -54,9 +54,9 @@ test_that('stan_glm execution', { test_that('stan prediction', { skip_if_not_installed("rstanarm") - uni_stan <- stan_glm(Sepal.Length ~ Sepal.Width + Petal.Width + Petal.Length, data = iris, seed = 123) + uni_stan <- rstanarm::stan_glm(Sepal.Length ~ Sepal.Width + Petal.Width + Petal.Length, data = iris, seed = 123) uni_pred <- unname(predict(uni_stan, newdata = iris[1:5, ])) - inl_stan <- stan_glm(Sepal.Width ~ log(Sepal.Length) + Species, data = iris, seed = 123, chains = 1) + inl_stan <- rstanarm::stan_glm(Sepal.Width ~ log(Sepal.Length) + Species, data = iris, seed = 123, chains = 1) inl_pred <- unname(predict(inl_stan, newdata = iris[1:5, c("Sepal.Length", "Species")])) res_xy <- fit_xy( @@ -103,11 +103,11 @@ test_that('stan intervals', { level = 0.93) prediction_stan <- - predictive_interval(res_xy$fit, newdata = iris[1:5, ], seed = 13, - prob = 0.93) + rstanarm::predictive_interval(res_xy$fit, newdata = iris[1:5, ], seed = 13, + prob = 0.93) - stan_post <- posterior_linpred(res_xy$fit, newdata = iris[1:5, ], - seed = 13) + stan_post <- rstanarm::posterior_linpred(res_xy$fit, newdata = iris[1:5, ], + seed = 13) stan_lower <- apply(stan_post, 2, quantile, prob = 0.035) stan_upper <- apply(stan_post, 2, quantile, prob = 0.965) diff --git a/tests/testthat/test_logistic_reg.R b/tests/testthat/test_logistic_reg.R index c74b0c492..b4d234631 100644 --- a/tests/testthat/test_logistic_reg.R +++ b/tests/testthat/test_logistic_reg.R @@ -244,23 +244,24 @@ test_that('glm execution', { ) ) - # passes interactively but not on R CMD check - # glm_form_catch <- fit( - # lc_basic, - # funded_amnt ~ term, - # data = lending_club, - # - # control = caught_ctrl - # ) - # expect_true(inherits(glm_form_catch$fit, "try-error")) + # wrong outcome type + expect_error( + glm_form_catch <- fit( + lc_basic, + funded_amnt ~ term, + data = lending_club, + control = caught_ctrl + ) + ) - glm_xy_catch <- fit_xy( - lc_basic, - control = caught_ctrl, - x = lending_club[, num_pred], - y = lending_club$total_bal_il + expect_error( + glm_xy_catch <- fit_xy( + lc_basic, + control = caught_ctrl, + x = lending_club[, num_pred], + y = lending_club$total_bal_il + ) ) - expect_true(inherits(glm_xy_catch$fit, "try-error")) }) test_that('glm prediction', { diff --git a/tests/testthat/test_logistic_reg_glmnet.R b/tests/testthat/test_logistic_reg_glmnet.R index e59533209..8dddbb48a 100644 --- a/tests/testthat/test_logistic_reg_glmnet.R +++ b/tests/testthat/test_logistic_reg_glmnet.R @@ -34,14 +34,14 @@ test_that('glmnet execution', { regexp = NA ) - glmnet_xy_catch <- fit_xy( - lc_basic, - x = lending_club[, num_pred], - y = lending_club$total_bal_il, - control = caught_ctrl + expect_error( + glmnet_xy_catch <- fit_xy( + lc_basic, + x = lending_club[, num_pred], + y = lending_club$total_bal_il, + control = caught_ctrl + ) ) - expect_true(inherits(glmnet_xy_catch$fit, "try-error")) - }) test_that('glmnet prediction, one lambda', { diff --git a/tests/testthat/test_logistic_reg_stan.R b/tests/testthat/test_logistic_reg_stan.R index 0a322d1e4..75b8635ce 100644 --- a/tests/testthat/test_logistic_reg_stan.R +++ b/tests/testthat/test_logistic_reg_stan.R @@ -24,6 +24,8 @@ quiet_ctrl <- fit_control(verbosity = 0, catch = TRUE) test_that('stan_glm execution', { skip_if_not_installed("rstanarm") + library(rstanarm) + expect_error( res <- fit( lc_basic, @@ -149,8 +151,8 @@ test_that('stan intervals', { std_error = TRUE) stan_post <- - posterior_linpred(res_form$fit, newdata = lending_club[1:5, ], seed = 13, - prob = 0.93, transform = TRUE) + rstanarm::posterior_linpred(res_form$fit, newdata = lending_club[1:5, ], seed = 13, + prob = 0.93, transform = TRUE) stan_lower <- apply(stan_post, 2, quantile, prob = 0.035) stan_upper <- apply(stan_post, 2, quantile, prob = 0.965) diff --git a/tests/testthat/test_multinom_reg_glmnet.R b/tests/testthat/test_multinom_reg_glmnet.R index 6043aae6e..ab1b1a8d3 100644 --- a/tests/testthat/test_multinom_reg_glmnet.R +++ b/tests/testthat/test_multinom_reg_glmnet.R @@ -29,14 +29,14 @@ test_that('glmnet execution', { regexp = NA ) - glmnet_xy_catch <- fit_xy( - multinom_reg() %>% set_engine("glmnet"), - x = iris[, 2:5], - y = iris$Sepal.Length, - , - control = caught_ctrl + expect_error( + glmnet_xy_catch <- fit_xy( + multinom_reg() %>% set_engine("glmnet"), + x = iris[, 2:5], + y = iris$Sepal.Length, + control = caught_ctrl + ) ) - expect_true(inherits(glmnet_xy_catch$fit, "try-error")) }) diff --git a/tests/testthat/test_nearest_neighbor_kknn.R b/tests/testthat/test_nearest_neighbor_kknn.R index 1d764d0aa..b0362a5aa 100644 --- a/tests/testthat/test_nearest_neighbor_kknn.R +++ b/tests/testthat/test_nearest_neighbor_kknn.R @@ -20,6 +20,7 @@ quiet_ctrl <- fit_control(verbosity = 0, catch = TRUE) test_that('kknn execution', { skip_if_not_installed("kknn") + library(kknn) # continuous # expect no error @@ -78,7 +79,7 @@ test_that('kknn prediction', { # nominal res_xy_nom <- fit_xy( - iris_basic, + iris_basic %>% set_mode("classification"), control = ctrl, x = iris[, c("Sepal.Length", "Petal.Width")], y = iris$Species @@ -89,11 +90,11 @@ test_that('kknn prediction', { newdata = iris[1:5, c("Sepal.Length", "Petal.Width")] ) - expect_equal(uni_pred_nom, predict_class(res_xy_nom, iris[1:5, c("Sepal.Length", "Petal.Width")])) + expect_equal(uni_pred_nom, parsnip:::predict_class(res_xy_nom, iris[1:5, c("Sepal.Length", "Petal.Width")])) # continuous - formula interface res_form <- fit( - iris_basic, + iris_basic %>% set_mode("regression"), Sepal.Length ~ log(Sepal.Width) + Species, data = iris, control = ctrl diff --git a/tests/testthat/test_predict_formats.R b/tests/testthat/test_predict_formats.R index cd10d2add..d12743f4b 100644 --- a/tests/testthat/test_predict_formats.R +++ b/tests/testthat/test_predict_formats.R @@ -58,3 +58,22 @@ test_that('non-standard levels', { expect_equal(names(predict_classprob(lr_fit_2, new_data = class_dat2[1:5,-1])), c("2low", "high+values")) }) + +test_that('non-factor classification', { + expect_error( + logistic_reg() %>% + set_engine("glm") %>% + fit(Species ~ ., data = iris %>% mutate(Species = Species == "setosa")) + ) + expect_error( + logistic_reg() %>% + set_engine("glm") %>% + fit(Species ~ ., data = iris %>% mutate(Species = ifelse(Species == "setosa", 1, 0))) + ) + expect_error( + multinom_reg() %>% + set_engine("glmnet") %>% + fit(Species ~ ., data = iris %>% mutate(Species = as.character(Species))) + ) +}) + diff --git a/tests/testthat/test_rand_forest_randomForest.R b/tests/testthat/test_rand_forest_randomForest.R index 35937b244..888dc05da 100644 --- a/tests/testthat/test_rand_forest_randomForest.R +++ b/tests/testthat/test_rand_forest_randomForest.R @@ -66,13 +66,14 @@ test_that('randomForest classification execution', { # ) # expect_true(inherits(randomForest_form_catch$fit, "try-error")) - randomForest_xy_catch <- fit_xy( - bad_rf_cls, - x = lending_club[, num_pred], - y = lending_club$total_bal_il, - control = caught_ctrl + expect_error( + fit_xy( + bad_rf_cls, + x = lending_club[, num_pred], + y = lending_club$total_bal_il, + control = caught_ctrl + ) ) - expect_true(inherits(randomForest_xy_catch$fit, "try-error")) }) diff --git a/tests/testthat/test_rand_forest_ranger.R b/tests/testthat/test_rand_forest_ranger.R index 82d767c4b..330afb3e5 100644 --- a/tests/testthat/test_rand_forest_ranger.R +++ b/tests/testthat/test_rand_forest_ranger.R @@ -86,10 +86,9 @@ test_that('ranger classification prediction', { skip_if_not_installed("ranger") xy_fit <- fit_xy( - rand_forest() %>% set_engine("ranger"), + rand_forest() %>% set_mode("classification") %>% set_engine("ranger"), x = lending_club[, num_pred], y = lending_club$Class, - control = ctrl ) @@ -99,7 +98,7 @@ test_that('ranger classification prediction', { expect_equal(xy_pred, predict_class(xy_fit, new_data = lending_club[1:6, num_pred])) form_fit <- fit( - rand_forest() %>% set_engine("ranger"), + rand_forest() %>% set_mode("classification") %>% set_engine("ranger"), Class ~ funded_amnt + int_rate, data = lending_club, @@ -119,7 +118,7 @@ test_that('ranger classification probabilities', { skip_if_not_installed("ranger") xy_fit <- fit_xy( - rand_forest() %>% set_engine("ranger", seed = 3566), + rand_forest() %>% set_mode("classification") %>% set_engine("ranger", seed = 3566), x = lending_club[, num_pred], y = lending_club$Class, @@ -134,7 +133,7 @@ test_that('ranger classification probabilities', { expect_equivalent(xy_pred[1,], one_row) form_fit <- fit( - rand_forest() %>% set_engine("ranger", seed = 3566), + rand_forest() %>% set_mode("classification") %>% set_engine("ranger", seed = 3566), Class ~ funded_amnt + int_rate, data = lending_club, @@ -149,7 +148,6 @@ test_that('ranger classification probabilities', { rand_forest() %>% set_engine("ranger", probability = FALSE), x = lending_club[, num_pred], y = lending_club$Class, - control = ctrl ) @@ -348,7 +346,7 @@ test_that('ranger classification prediction', { skip_if_not_installed("ranger") xy_class_fit <- - rand_forest() %>% set_engine("ranger") %>% + rand_forest() %>% set_mode("classification") %>% set_engine("ranger") %>% fit_xy( x = iris[, 1:4], y = iris$Species, @@ -366,6 +364,7 @@ test_that('ranger classification prediction', { xy_prob_fit <- rand_forest() %>% + set_mode("classification") %>% set_engine("ranger") %>% fit_xy( x = iris[, 1:4], From a620edb24d9496b7dbe575c157d45c1f5595f433 Mon Sep 17 00:00:00 2001 From: topepo Date: Wed, 27 Feb 2019 16:03:41 -0500 Subject: [PATCH 02/34] testing out adding modeling pacakges to suggests --- DESCRIPTION | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/DESCRIPTION b/DESCRIPTION index 61788129c..d21f8279a 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -38,4 +38,12 @@ Suggests: keras, xgboost, covr, - sparklyr + sparklyr, + earth, + glmnet, + kernlab, + kknn, + randomForest, + ranger, + rpart, + rstanarm From 147eea859c9d22d562ba3a51a3a02228f9ac66c3 Mon Sep 17 00:00:00 2001 From: topepo Date: Wed, 27 Feb 2019 19:57:47 -0500 Subject: [PATCH 03/34] first attempt at getting around CXX14 travis issues --- .travis.yml | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/.travis.yml b/.travis.yml index ebf585975..b76000fb7 100644 --- a/.travis.yml +++ b/.travis.yml @@ -14,6 +14,14 @@ r: - release - devel + +addons: + apt: + sources: + - ubuntu-toolchain-r-test + packages: + - g++-6 + env: global: - KERAS_BACKEND="tensorflow" @@ -69,6 +77,9 @@ before_install: - sudo apt-get -y install libnlopt-dev - sudo apt-get update - sudo apt-get -y install python3 + - sudo update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-6 100 + - echo "** Overriding src/Makevars and removing C++14 on Travis only" + - sed -i 's|CXX_STD = CXX14||' src/Makevars after_success: - Rscript -e 'covr::codecov()' From d41bef3206ba5601565cf44e3e107c5a6110ba67 Mon Sep 17 00:00:00 2001 From: topepo Date: Thu, 28 Feb 2019 11:53:21 -0500 Subject: [PATCH 04/34] second attempt at getting around CXX14 travis issues --- .travis.yml | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/.travis.yml b/.travis.yml index b76000fb7..86a1ee1d5 100644 --- a/.travis.yml +++ b/.travis.yml @@ -22,6 +22,7 @@ addons: packages: - g++-6 + env: global: - KERAS_BACKEND="tensorflow" @@ -77,9 +78,7 @@ before_install: - sudo apt-get -y install libnlopt-dev - sudo apt-get update - sudo apt-get -y install python3 - - sudo update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-6 100 - - echo "** Overriding src/Makevars and removing C++14 on Travis only" - - sed -i 's|CXX_STD = CXX14||' src/Makevars + after_success: - Rscript -e 'covr::codecov()' From 5d26fec991c9b9e1f98c445a7dac0ffc7e3789cd Mon Sep 17 00:00:00 2001 From: topepo Date: Thu, 28 Feb 2019 13:04:57 -0500 Subject: [PATCH 05/34] third attempt at getting around CXX14 travis issues (xenial) --- .travis.yml | 10 +--------- 1 file changed, 1 insertion(+), 9 deletions(-) diff --git a/.travis.yml b/.travis.yml index 86a1ee1d5..ccbf5c385 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,7 +1,7 @@ # R for travis: see documentation at https://docs.travis-ci.com/user/languages/r language: r -dist: trusty +dist: xenial sudo: true # until generics is finalized @@ -15,14 +15,6 @@ r: - devel -addons: - apt: - sources: - - ubuntu-toolchain-r-test - packages: - - g++-6 - - env: global: - KERAS_BACKEND="tensorflow" From b734323fa0cdc8b08506a223fd60538e45f7cb22 Mon Sep 17 00:00:00 2001 From: topepo Date: Thu, 28 Feb 2019 13:09:31 -0500 Subject: [PATCH 06/34] fourth attempt at getting around CXX14 travis issues --- .travis.yml | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index ccbf5c385..68590848d 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,7 +1,7 @@ # R for travis: see documentation at https://docs.travis-ci.com/user/languages/r language: r -dist: xenial +dist: trusty sudo: true # until generics is finalized @@ -25,6 +25,17 @@ matrix: allow_failures: - r: 3.1 - r: 3.2 + include: + - os: linux + addons: + apt: + sources: + - ubuntu-toolchain-r-test + packages: + - g++-7 + env: + - MATRIX_EVAL="CC=gcc-7 && CXX=g++-7" + r_binary_packages: - rstan From f9f6d294a6749d6e7132969429a6100da43fbb86 Mon Sep 17 00:00:00 2001 From: topepo Date: Thu, 28 Feb 2019 13:37:07 -0500 Subject: [PATCH 07/34] fifth attempt at getting around CXX14 travis issues --- .travis.yml | 16 ++-------------- 1 file changed, 2 insertions(+), 14 deletions(-) diff --git a/.travis.yml b/.travis.yml index 68590848d..8dc4b064a 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,9 +1,6 @@ # R for travis: see documentation at https://docs.travis-ci.com/user/languages/r language: r -dist: trusty -sudo: true - # until generics is finalized warnings_are_errors: false @@ -25,17 +22,8 @@ matrix: allow_failures: - r: 3.1 - r: 3.2 - include: - - os: linux - addons: - apt: - sources: - - ubuntu-toolchain-r-test - packages: - - g++-7 - env: - - MATRIX_EVAL="CC=gcc-7 && CXX=g++-7" - + include: + - dist: xenial r_binary_packages: - rstan From 2d3d21f87bc453946296a8cc1bf6e2691a1b84ad Mon Sep 17 00:00:00 2001 From: topepo Date: Thu, 28 Feb 2019 14:11:14 -0500 Subject: [PATCH 08/34] sizth attempt at getting around CXX14 travis issues --- .travis.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.travis.yml b/.travis.yml index 8dc4b064a..5a74d4ee5 100644 --- a/.travis.yml +++ b/.travis.yml @@ -3,6 +3,7 @@ language: r # until generics is finalized warnings_are_errors: false +sudo: true r: - 3.1 From 71e6178886de1f21a1f5060ee67a14c9231dcaf3 Mon Sep 17 00:00:00 2001 From: topepo Date: Thu, 28 Feb 2019 15:39:52 -0500 Subject: [PATCH 09/34] abandoning rstanarm on travis --- .travis.yml | 3 --- DESCRIPTION | 3 +-- 2 files changed, 1 insertion(+), 5 deletions(-) diff --git a/.travis.yml b/.travis.yml index 5a74d4ee5..cf16b3905 100644 --- a/.travis.yml +++ b/.travis.yml @@ -27,8 +27,6 @@ matrix: - dist: xenial r_binary_packages: - - rstan - - rstanarm - RCurl - dplyr - glue @@ -41,7 +39,6 @@ r_binary_packages: - scales - tibble - ggplot2 - - StanHeaders - Rcpp - RcppEigen - BH diff --git a/DESCRIPTION b/DESCRIPTION index d21f8279a..1a94c909b 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -45,5 +45,4 @@ Suggests: kknn, randomForest, ranger, - rpart, - rstanarm + rpart From 8649a6265ed7cb3e1421bc6f86dbfffba6eefe88 Mon Sep 17 00:00:00 2001 From: topepo Date: Thu, 28 Feb 2019 15:58:52 -0500 Subject: [PATCH 10/34] cleaned the travis house to see what runs and fails --- .travis.yml | 38 +------------------------------------- 1 file changed, 1 insertion(+), 37 deletions(-) diff --git a/.travis.yml b/.travis.yml index cf16b3905..053460d8d 100644 --- a/.travis.yml +++ b/.travis.yml @@ -5,52 +5,16 @@ language: r warnings_are_errors: false sudo: true -r: -- 3.1 -- 3.2 -- oldrel -- release -- devel - - env: global: - KERAS_BACKEND="tensorflow" - MAKEFLAGS="-j 2" -# until we troubleshoot these issues + matrix: - allow_failures: - - r: 3.1 - - r: 3.2 include: - dist: xenial -r_binary_packages: - - RCurl - - dplyr - - glue - - magrittr - - stringi - - stringr - - munsell - - rlang - - reshape2 - - scales - - tibble - - ggplot2 - - Rcpp - - RcppEigen - - BH - - glmnet - - earth - - sparklyr - - flexsurv - - ranger - - randomforest - - xgboost - - C50 - cache: packages: true directories: From cb1abfb831ad091bdafae3d0f732390733a91085 Mon Sep 17 00:00:00 2001 From: topepo Date: Thu, 28 Feb 2019 16:35:25 -0500 Subject: [PATCH 11/34] no rstanarm and back to trusty --- .travis.yml | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/.travis.yml b/.travis.yml index 053460d8d..724bc7e79 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,9 +1,22 @@ # R for travis: see documentation at https://docs.travis-ci.com/user/languages/r language: r +dist: trusty +sudo: true # until generics is finalized warnings_are_errors: false -sudo: true + +r: +- 3.1 +- 3.2 +- oldrel +- release +- devel + +matrix: + allow_failures: + - r: 3.1 + - r: 3.2 env: global: @@ -11,10 +24,6 @@ env: - MAKEFLAGS="-j 2" -matrix: - include: - - dist: xenial - cache: packages: true directories: From 26be9296b606f421767c04df0f7f1a84d4420d98 Mon Sep 17 00:00:00 2001 From: topepo Date: Thu, 28 Feb 2019 16:42:36 -0500 Subject: [PATCH 12/34] trying to avoid travis failures for devtools MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ``` * installing *source* package ‘devtools’ ... ** package ‘devtools’ successfully unpacked and MD5 sums checked ** R ** inst ** byte-compile and prepare package for lazy loading Error in loadNamespace(j <- i[[1L]], c(lib.loc, .libPaths()), versionCheck = vI[[j]]) : there is no package called ‘magrittr’ ERROR: lazy loading failed for package ‘devtools’ * removing ‘/home/travis/R/Library/devtools’ * restoring previous ‘/home/travis/R/Library/devtools’ The downloaded source packages are in ‘/tmp/RtmpUhu1j4/downloaded_packages’ Warning message: In install.packages(c("devtools")) : installation of package ‘devtools’ had non-zero exit status ``` --- .travis.yml | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/.travis.yml b/.travis.yml index 724bc7e79..56e7a85ac 100644 --- a/.travis.yml +++ b/.travis.yml @@ -18,6 +18,11 @@ matrix: - r: 3.1 - r: 3.2 +r_binary_packages: + - devtools + - magrittr + + env: global: - KERAS_BACKEND="tensorflow" From 3ffaa345925f4b05bc1550dcb698aae23978a817 Mon Sep 17 00:00:00 2001 From: topepo Date: Fri, 1 Mar 2019 12:52:58 -0500 Subject: [PATCH 13/34] back to original travis file --- .travis.yml | 40 ++++++++++++++++++++++++++++++---------- 1 file changed, 30 insertions(+), 10 deletions(-) diff --git a/.travis.yml b/.travis.yml index 56e7a85ac..ae430a7b8 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,5 +1,6 @@ # R for travis: see documentation at https://docs.travis-ci.com/user/languages/r language: r + dist: trusty sudo: true @@ -13,21 +14,41 @@ r: - release - devel +env: + global: + - KERAS_BACKEND="tensorflow" + - MAKEFLAGS="-j 2" + +# until we troubleshoot these issues matrix: allow_failures: - r: 3.1 - r: 3.2 r_binary_packages: - - devtools + - RCurl + - dplyr + - glue - magrittr - - -env: - global: - - KERAS_BACKEND="tensorflow" - - MAKEFLAGS="-j 2" - + - stringi + - stringr + - munsell + - rlang + - reshape2 + - scales + - tibble + - ggplot2 + - Rcpp + - RcppEigen + - BH + - glmnet + - earth + - sparklyr + - flexsurv + - ranger + - randomforest + - xgboost + - C50 cache: packages: true @@ -46,6 +67,5 @@ before_install: - sudo apt-get update - sudo apt-get -y install python3 - after_success: - - Rscript -e 'covr::codecov()' + - Rscript -e 'covr::codecov()' \ No newline at end of file From 0102dfd758dd758d78e760b30ecdeffb2f3cd8f6 Mon Sep 17 00:00:00 2001 From: topepo Date: Fri, 1 Mar 2019 13:01:46 -0500 Subject: [PATCH 14/34] reformatting --- .travis.yml | 57 +++++++++++++++++++++++++++-------------------------- 1 file changed, 29 insertions(+), 28 deletions(-) diff --git a/.travis.yml b/.travis.yml index ae430a7b8..e480b2df9 100644 --- a/.travis.yml +++ b/.travis.yml @@ -8,11 +8,11 @@ sudo: true warnings_are_errors: false r: -- 3.1 -- 3.2 -- oldrel -- release -- devel + - 3.1 + - 3.2 + - oldrel + - release + - devel env: global: @@ -27,28 +27,28 @@ matrix: r_binary_packages: - RCurl - - dplyr - - glue - - magrittr - - stringi - - stringr - - munsell - - rlang - - reshape2 - - scales - - tibble - - ggplot2 - - Rcpp - - RcppEigen - - BH - - glmnet - - earth - - sparklyr - - flexsurv - - ranger - - randomforest - - xgboost - - C50 + - dplyr + - glue + - magrittr + - stringi + - stringr + - munsell + - rlang + - reshape2 + - scales + - tibble + - ggplot2 + - Rcpp + - RcppEigen + - BH + - glmnet + - earth + - sparklyr + - flexsurv + - ranger + - randomforest + - xgboost + - C50 cache: packages: true @@ -68,4 +68,5 @@ before_install: - sudo apt-get -y install python3 after_success: - - Rscript -e 'covr::codecov()' \ No newline at end of file + - Rscript -e 'covr::codecov()' + From ec54ba84c30965e2def8d57f9a922196f9bb6f41 Mon Sep 17 00:00:00 2001 From: topepo Date: Sat, 2 Mar 2019 11:18:21 -0500 Subject: [PATCH 15/34] R-devel complains about calling by namespace without loading --- tests/testthat/test_boost_tree_C50.R | 3 ++- tests/testthat/test_linear_reg_stan.R | 13 +++++++------ tests/testthat/test_logistic_reg_stan.R | 5 +++-- 3 files changed, 12 insertions(+), 9 deletions(-) diff --git a/tests/testthat/test_boost_tree_C50.R b/tests/testthat/test_boost_tree_C50.R index e712c5ab1..d6a6e30e1 100644 --- a/tests/testthat/test_boost_tree_C50.R +++ b/tests/testthat/test_boost_tree_C50.R @@ -116,11 +116,12 @@ test_that('C5.0 probabilities', { test_that('submodel prediction', { skip_if_not_installed("C50") + library(C50) vars <- c("female", "tenure", "total_charges", "phone_service", "monthly_charges") class_fit <- boost_tree(trees = 20, mode = "classification") %>% - set_engine("C5.0", control = C50::C5.0Control(earlyStopping = FALSE)) %>% + set_engine("C5.0", control = C5.0Control(earlyStopping = FALSE)) %>% fit(churn ~ ., data = wa_churn[-(1:4), c("churn", vars)]) pred_class <- predict(class_fit$fit, wa_churn[1:4, vars], trials = 4, type = "prob") diff --git a/tests/testthat/test_linear_reg_stan.R b/tests/testthat/test_linear_reg_stan.R index 08555e0df..87a71bafa 100644 --- a/tests/testthat/test_linear_reg_stan.R +++ b/tests/testthat/test_linear_reg_stan.R @@ -53,10 +53,11 @@ test_that('stan_glm execution', { test_that('stan prediction', { skip_if_not_installed("rstanarm") + library(rstanarm) - uni_stan <- rstanarm::stan_glm(Sepal.Length ~ Sepal.Width + Petal.Width + Petal.Length, data = iris, seed = 123) + uni_stan <- stan_glm(Sepal.Length ~ Sepal.Width + Petal.Width + Petal.Length, data = iris, seed = 123) uni_pred <- unname(predict(uni_stan, newdata = iris[1:5, ])) - inl_stan <- rstanarm::stan_glm(Sepal.Width ~ log(Sepal.Length) + Species, data = iris, seed = 123, chains = 1) + inl_stan <- stan_glm(Sepal.Width ~ log(Sepal.Length) + Species, data = iris, seed = 123, chains = 1) inl_pred <- unname(predict(inl_stan, newdata = iris[1:5, c("Sepal.Length", "Species")])) res_xy <- fit_xy( @@ -103,11 +104,11 @@ test_that('stan intervals', { level = 0.93) prediction_stan <- - rstanarm::predictive_interval(res_xy$fit, newdata = iris[1:5, ], seed = 13, - prob = 0.93) + predictive_interval(res_xy$fit, newdata = iris[1:5, ], seed = 13, + prob = 0.93) - stan_post <- rstanarm::posterior_linpred(res_xy$fit, newdata = iris[1:5, ], - seed = 13) + stan_post <- posterior_linpred(res_xy$fit, newdata = iris[1:5, ], + seed = 13) stan_lower <- apply(stan_post, 2, quantile, prob = 0.035) stan_upper <- apply(stan_post, 2, quantile, prob = 0.965) diff --git a/tests/testthat/test_logistic_reg_stan.R b/tests/testthat/test_logistic_reg_stan.R index 75b8635ce..a5cc62338 100644 --- a/tests/testthat/test_logistic_reg_stan.R +++ b/tests/testthat/test_logistic_reg_stan.R @@ -126,6 +126,7 @@ test_that('stan_glm probability', { test_that('stan intervals', { skip_if_not_installed("rstanarm") + library(rstanarm) res_form <- fit( logistic_reg() %>% set_engine("stan", seed = 1333, chains = 1), @@ -151,8 +152,8 @@ test_that('stan intervals', { std_error = TRUE) stan_post <- - rstanarm::posterior_linpred(res_form$fit, newdata = lending_club[1:5, ], seed = 13, - prob = 0.93, transform = TRUE) + posterior_linpred(res_form$fit, newdata = lending_club[1:5, ], seed = 13, + prob = 0.93, transform = TRUE) stan_lower <- apply(stan_post, 2, quantile, prob = 0.035) stan_upper <- apply(stan_post, 2, quantile, prob = 0.965) From faca552969a4a039aa6d28af26cf13e2b3c5de95 Mon Sep 17 00:00:00 2001 From: topepo Date: Sat, 2 Mar 2019 11:18:48 -0500 Subject: [PATCH 16/34] seventh attempt at getting around CXX14 travis issues --- .travis.yml | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/.travis.yml b/.travis.yml index e480b2df9..14f93255e 100644 --- a/.travis.yml +++ b/.travis.yml @@ -14,12 +14,7 @@ r: - release - devel -env: - global: - - KERAS_BACKEND="tensorflow" - - MAKEFLAGS="-j 2" -# until we troubleshoot these issues matrix: allow_failures: - r: 3.1 @@ -56,11 +51,23 @@ cache: - $HOME/.keras - $HOME/.cache/pip +env: + global: + - KERAS_BACKEND="tensorflow" + - MAKEFLAGS="-j 2" + +addons: + apt: + sources: + - ubuntu-toolchain-r-test + packages: + g++-6 before_script: - python -m pip install --upgrade --ignore-installed --user travis pip setuptools wheel virtualenv - python -m pip install --upgrade --ignore-installed --user travis keras h5py pyyaml requests Pillow scipy theano - R -e 'tensorflow::install_tensorflow()' + - mkdir -p ~/.R && echo "CXX14=g++-6` > ~/.R/Makevars before_install: - sudo apt-get -y install libnlopt-dev From 98db3086da409d22d3d4e77b9188eb65a21af28b Mon Sep 17 00:00:00 2001 From: topepo Date: Sat, 2 Mar 2019 11:34:13 -0500 Subject: [PATCH 17/34] eigth attempt at getting around CXX14 travis issues --- .travis.yml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 14f93255e..23010c5ee 100644 --- a/.travis.yml +++ b/.travis.yml @@ -64,10 +64,12 @@ addons: g++-6 before_script: + - mkdir -p ~/.R && echo "CXX14=g++-6` > ~/.R/Makevars + - cd ~ - python -m pip install --upgrade --ignore-installed --user travis pip setuptools wheel virtualenv - python -m pip install --upgrade --ignore-installed --user travis keras h5py pyyaml requests Pillow scipy theano - R -e 'tensorflow::install_tensorflow()' - - mkdir -p ~/.R && echo "CXX14=g++-6` > ~/.R/Makevars + before_install: - sudo apt-get -y install libnlopt-dev From d0b77699eff77bfd2ff766ebdff588ee5ea8564c Mon Sep 17 00:00:00 2001 From: topepo Date: Sat, 2 Mar 2019 13:30:51 -0500 Subject: [PATCH 18/34] bad backtick! --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 23010c5ee..20a4bb779 100644 --- a/.travis.yml +++ b/.travis.yml @@ -64,7 +64,7 @@ addons: g++-6 before_script: - - mkdir -p ~/.R && echo "CXX14=g++-6` > ~/.R/Makevars + - mkdir -p ~/.R && echo "CXX14=g++-6" > ~/.R/Makevars - cd ~ - python -m pip install --upgrade --ignore-installed --user travis pip setuptools wheel virtualenv - python -m pip install --upgrade --ignore-installed --user travis keras h5py pyyaml requests Pillow scipy theano From e8eee0008ff20c70dea711190528dfcd41901d7a Mon Sep 17 00:00:00 2001 From: topepo Date: Sat, 2 Mar 2019 13:47:37 -0500 Subject: [PATCH 19/34] moved makevars stuff to before_install --- .travis.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index 20a4bb779..f7d8c1934 100644 --- a/.travis.yml +++ b/.travis.yml @@ -64,8 +64,6 @@ addons: g++-6 before_script: - - mkdir -p ~/.R && echo "CXX14=g++-6" > ~/.R/Makevars - - cd ~ - python -m pip install --upgrade --ignore-installed --user travis pip setuptools wheel virtualenv - python -m pip install --upgrade --ignore-installed --user travis keras h5py pyyaml requests Pillow scipy theano - R -e 'tensorflow::install_tensorflow()' @@ -75,6 +73,8 @@ before_install: - sudo apt-get -y install libnlopt-dev - sudo apt-get update - sudo apt-get -y install python3 + - mkdir -p ~/.R && echo "CXX14=g++-6" > ~/.R/Makevars + after_success: - Rscript -e 'covr::codecov()' From eb3221c3e1faf23bee6223e578259629b358b89c Mon Sep 17 00:00:00 2001 From: topepo Date: Sat, 2 Mar 2019 14:03:44 -0500 Subject: [PATCH 20/34] adding C50 and rstanarm back into travis builds --- DESCRIPTION | 2 ++ 1 file changed, 2 insertions(+) diff --git a/DESCRIPTION b/DESCRIPTION index 1a94c909b..ce249f6be 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -38,6 +38,8 @@ Suggests: keras, xgboost, covr, + C50, + rstanarm, sparklyr, earth, glmnet, From fa874d2e198e4176cb91c55cfe1a67dffd8868ac Mon Sep 17 00:00:00 2001 From: topepo Date: Sat, 2 Mar 2019 14:30:55 -0500 Subject: [PATCH 21/34] get binaries for stan packages --- .travis.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.travis.yml b/.travis.yml index f7d8c1934..91d591718 100644 --- a/.travis.yml +++ b/.travis.yml @@ -44,6 +44,9 @@ r_binary_packages: - randomforest - xgboost - C50 + - rstan + - StanHeaders + - rstanarm cache: packages: true From 5fbcf2d956c4285f5473b1c284a3c31ec86a4819 Mon Sep 17 00:00:00 2001 From: topepo Date: Sat, 2 Mar 2019 14:58:53 -0500 Subject: [PATCH 22/34] CXX14FLAGS for rstan --- .travis.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.travis.yml b/.travis.yml index 91d591718..49d889b04 100644 --- a/.travis.yml +++ b/.travis.yml @@ -77,6 +77,7 @@ before_install: - sudo apt-get update - sudo apt-get -y install python3 - mkdir -p ~/.R && echo "CXX14=g++-6" > ~/.R/Makevars + - echo "CXX14FLAGS += -fPIC" >> ~/.R/Makevars after_success: From 75796734955848bd7e28eb73ea45d34732fde4e8 Mon Sep 17 00:00:00 2001 From: topepo Date: Sat, 2 Mar 2019 15:45:51 -0500 Subject: [PATCH 23/34] more binaries --- .travis.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.travis.yml b/.travis.yml index 49d889b04..d1b91dd73 100644 --- a/.travis.yml +++ b/.travis.yml @@ -47,6 +47,7 @@ r_binary_packages: - rstan - StanHeaders - rstanarm + - RcppEigen cache: packages: true From cb864e101eee6c8106d079c65a0580dc3abd8e31 Mon Sep 17 00:00:00 2001 From: topepo Date: Sat, 2 Mar 2019 16:11:40 -0500 Subject: [PATCH 24/34] no stan --- .travis.yml | 5 +---- tests/testthat/test_linear_reg_stan.R | 1 - tests/testthat/test_logistic_reg_stan.R | 2 -- 3 files changed, 1 insertion(+), 7 deletions(-) diff --git a/.travis.yml b/.travis.yml index d1b91dd73..e45533ed3 100644 --- a/.travis.yml +++ b/.travis.yml @@ -44,10 +44,7 @@ r_binary_packages: - randomforest - xgboost - C50 - - rstan - - StanHeaders - - rstanarm - - RcppEigen + cache: packages: true diff --git a/tests/testthat/test_linear_reg_stan.R b/tests/testthat/test_linear_reg_stan.R index 87a71bafa..4891e65e1 100644 --- a/tests/testthat/test_linear_reg_stan.R +++ b/tests/testthat/test_linear_reg_stan.R @@ -53,7 +53,6 @@ test_that('stan_glm execution', { test_that('stan prediction', { skip_if_not_installed("rstanarm") - library(rstanarm) uni_stan <- stan_glm(Sepal.Length ~ Sepal.Width + Petal.Width + Petal.Length, data = iris, seed = 123) uni_pred <- unname(predict(uni_stan, newdata = iris[1:5, ])) diff --git a/tests/testthat/test_logistic_reg_stan.R b/tests/testthat/test_logistic_reg_stan.R index a5cc62338..7ad3e7f15 100644 --- a/tests/testthat/test_logistic_reg_stan.R +++ b/tests/testthat/test_logistic_reg_stan.R @@ -24,8 +24,6 @@ quiet_ctrl <- fit_control(verbosity = 0, catch = TRUE) test_that('stan_glm execution', { skip_if_not_installed("rstanarm") - library(rstanarm) - expect_error( res <- fit( lc_basic, From e4b4ff6fafb2e186ab9428af149396726911b342 Mon Sep 17 00:00:00 2001 From: topepo Date: Sat, 2 Mar 2019 16:35:00 -0500 Subject: [PATCH 25/34] no stan (I mean it this time) --- DESCRIPTION | 1 - 1 file changed, 1 deletion(-) diff --git a/DESCRIPTION b/DESCRIPTION index ce249f6be..49ce7449e 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -39,7 +39,6 @@ Suggests: xgboost, covr, C50, - rstanarm, sparklyr, earth, glmnet, From 6a52205059d5a034a8a7074782d9a9d822b7b8af Mon Sep 17 00:00:00 2001 From: topepo Date: Sat, 2 Mar 2019 17:54:37 -0500 Subject: [PATCH 26/34] one last library call --- tests/testthat/test_logistic_reg_stan.R | 1 - 1 file changed, 1 deletion(-) diff --git a/tests/testthat/test_logistic_reg_stan.R b/tests/testthat/test_logistic_reg_stan.R index 7ad3e7f15..0a322d1e4 100644 --- a/tests/testthat/test_logistic_reg_stan.R +++ b/tests/testthat/test_logistic_reg_stan.R @@ -124,7 +124,6 @@ test_that('stan_glm probability', { test_that('stan intervals', { skip_if_not_installed("rstanarm") - library(rstanarm) res_form <- fit( logistic_reg() %>% set_engine("stan", seed = 1333, chains = 1), From 0a334b21f3f99e947e5d1b1b359eef6cef84271f Mon Sep 17 00:00:00 2001 From: topepo Date: Sat, 2 Mar 2019 20:17:14 -0500 Subject: [PATCH 27/34] fixed test case --- tests/testthat/test_logistic_reg_stan.R | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/tests/testthat/test_logistic_reg_stan.R b/tests/testthat/test_logistic_reg_stan.R index 0a322d1e4..efead71a7 100644 --- a/tests/testthat/test_logistic_reg_stan.R +++ b/tests/testthat/test_logistic_reg_stan.R @@ -33,13 +33,14 @@ test_that('stan_glm execution', { ) ) - stan_xy_catch <- fit_xy( - lc_basic, - control = caught_ctrl, - x = lending_club[, num_pred], - y = lending_club$total_bal_il + expect_error( + fit_xy( + lc_basic, + control = caught_ctrl, + x = lending_club[, num_pred], + y = lending_club$total_bal_il + ) ) - expect_true(inherits(stan_xy_catch$fit, "try-error")) }) From 1ff8ad25f01ebcb03c3cb5235f6030c34ccd9d8e Mon Sep 17 00:00:00 2001 From: topepo Date: Sat, 2 Mar 2019 20:51:19 -0500 Subject: [PATCH 28/34] more changes for r-devel --- DESCRIPTION | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/DESCRIPTION b/DESCRIPTION index 49ce7449e..dc9b84413 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -46,4 +46,6 @@ Suggests: kknn, randomForest, ranger, - rpart + rpart, + MASS, + nlme From d2c5ea4d951254e182130bbeca10620eb8a5f286 Mon Sep 17 00:00:00 2001 From: topepo Date: Sat, 2 Mar 2019 21:16:05 -0500 Subject: [PATCH 29/34] removed specific top-level stan calls --- tests/testthat/test_linear_reg_stan.R | 23 ++++--- tests/testthat/test_logistic_reg_stan.R | 87 +++++++++++++++++-------- 2 files changed, 75 insertions(+), 35 deletions(-) diff --git a/tests/testthat/test_linear_reg_stan.R b/tests/testthat/test_linear_reg_stan.R index 4891e65e1..b95629df9 100644 --- a/tests/testthat/test_linear_reg_stan.R +++ b/tests/testthat/test_linear_reg_stan.R @@ -102,14 +102,21 @@ test_that('stan intervals', { type = "pred_int", level = 0.93) - prediction_stan <- - predictive_interval(res_xy$fit, newdata = iris[1:5, ], seed = 13, - prob = 0.93) - - stan_post <- posterior_linpred(res_xy$fit, newdata = iris[1:5, ], - seed = 13) - stan_lower <- apply(stan_post, 2, quantile, prob = 0.035) - stan_upper <- apply(stan_post, 2, quantile, prob = 0.965) + # prediction_stan <- + # predictive_interval(res_xy$fit, newdata = iris[1:5, ], seed = 13, + # prob = 0.93) + # + # stan_post <- posterior_linpred(res_xy$fit, newdata = iris[1:5, ], + # seed = 13) + # stan_lower <- apply(stan_post, 2, quantile, prob = 0.035) + # stan_upper <- apply(stan_post, 2, quantile, prob = 0.965) + + stan_lower <- c(`1` = 4.93164991101342, `2` = 4.60197941230393, + `3` = 4.6671442757811, `4` = 4.74402724639963, + `5` = 4.99248110476701) + stan_upper <- c(`1` = 5.1002837047058, `2` = 4.77617561853506, + `3` = 4.83183673602725, `4` = 4.90844811805409, + `5` = 5.16979395659009) expect_equivalent(confidence_parsnip$.pred_lower, stan_lower) expect_equivalent(confidence_parsnip$.pred_upper, stan_upper) diff --git a/tests/testthat/test_logistic_reg_stan.R b/tests/testthat/test_logistic_reg_stan.R index efead71a7..63dbcf3d9 100644 --- a/tests/testthat/test_logistic_reg_stan.R +++ b/tests/testthat/test_logistic_reg_stan.R @@ -74,13 +74,16 @@ test_that('stan_glm prediction', { control = ctrl ) - form_pred <- - predict(res_form$fit, - newdata = lending_club[1:7, c("funded_amnt", "int_rate")]) - form_pred <- xy_fit$fit$family$linkinv(form_pred) - form_pred <- unname(form_pred) - form_pred <- ifelse(form_pred >= 0.5, "good", "bad") - form_pred <- factor(form_pred, levels = levels(lending_club$Class)) + # form_pred <- + # predict(res_form$fit, + # newdata = lending_club[1:7, c("funded_amnt", "int_rate")]) + # form_pred <- xy_fit$fit$family$linkinv(form_pred) + # form_pred <- unname(form_pred) + # form_pred <- ifelse(form_pred >= 0.5, "good", "bad") + # form_pred <- factor(form_pred, levels = levels(lending_club$Class)) + form_pred <- structure(c(2L, 2L, 2L, 2L, 2L, 2L, 2L), + .Label = c("bad", "good"), + class = "factor") expect_equal(form_pred, predict_class(res_form, lending_club[1:7, c("funded_amnt", "int_rate")])) }) @@ -113,12 +116,27 @@ test_that('stan_glm probability', { control = ctrl ) + # form_pred <- + # predict(res_form$fit, + # newdata = lending_club[1:7, c("funded_amnt", "int_rate")]) + # form_pred <- xy_fit$fit$family$linkinv(form_pred) + # form_pred <- tibble(bad = 1 - form_pred, good = form_pred) form_pred <- - predict(res_form$fit, - newdata = lending_club[1:7, c("funded_amnt", "int_rate")]) - form_pred <- xy_fit$fit$family$linkinv(form_pred) - form_pred <- tibble(bad = 1 - form_pred, good = form_pred) - expect_equal(form_pred, predict_classprob(res_form, lending_club[1:7, c("funded_amnt", "int_rate")])) + tibble::tribble( + ~bad, ~good, + 0.0451516541621074, 0.954848345837893, + 0.0663232780491584, 0.933676721950842, + 0.0425128897715562, 0.957487110228444, + 0.0442197030195933, 0.955780296980407, + 0.00135166763321781, 0.998648332366782, + 0.013776487556396, 0.986223512443604, + 0.00359938202445076, 0.996400617975549 + ) + expect_equal( + form_pred %>% as.data.frame(), + predict_classprob(res_form, lending_club[1:7, c("funded_amnt", "int_rate")]) %>% + as.data.frame() + ) }) @@ -149,26 +167,41 @@ test_that('stan intervals', { level = 0.93, std_error = TRUE) - stan_post <- - posterior_linpred(res_form$fit, newdata = lending_club[1:5, ], seed = 13, - prob = 0.93, transform = TRUE) - - stan_lower <- apply(stan_post, 2, quantile, prob = 0.035) - stan_upper <- apply(stan_post, 2, quantile, prob = 0.965) - stan_std <- apply(stan_post, 2, sd) + # stan_post <- + # posterior_linpred(res_form$fit, newdata = lending_club[1:5, ], seed = 13, + # prob = 0.93, transform = TRUE) + # + # stan_lower <- apply(stan_post, 2, quantile, prob = 0.035) + # stan_upper <- apply(stan_post, 2, quantile, prob = 0.965) + # stan_std <- apply(stan_post, 2, sd) + + stan_lower <- + c(`1` = 0.913925483690233, `2` = 0.841801274737206, `3` = 0.91056642931229, + `4` = 0.913619668586545, `5` = 0.987780279394871) + stan_upper <- + c(`1` = 0.978674663115785, `2` = 0.975178762720162, `3` = 0.984417491942267, + `4` = 0.979606072215269, `5` = 0.9999049778978) + stan_std <- + c(`1` = 0.0181025303127182, `2` = 0.0388665155739319, `3` = 0.0205886091162274, + `4` = 0.0181715224502082, `5` = 0.00405145389896896) expect_equivalent(confidence_parsnip$.pred_lower, stan_lower) expect_equivalent(confidence_parsnip$.pred_upper, stan_upper) expect_equivalent(confidence_parsnip$.std_error, stan_std) - stan_pred_post <- - posterior_predict(res_form$fit, newdata = lending_club[1:5, ], seed = 13, - prob = 0.93) - - stan_pred_lower <- apply(stan_pred_post, 2, quantile, prob = 0.035) - stan_pred_upper <- apply(stan_pred_post, 2, quantile, prob = 0.965) - stan_pred_std <- apply(stan_pred_post, 2, sd) - + # stan_pred_post <- + # posterior_predict(res_form$fit, newdata = lending_club[1:5, ], seed = 13, + # prob = 0.93) + # + # stan_pred_lower <- apply(stan_pred_post, 2, quantile, prob = 0.035) + # stan_pred_upper <- apply(stan_pred_post, 2, quantile, prob = 0.965) + # stan_pred_std <- apply(stan_pred_post, 2, sd) + + stan_pred_lower <- c(`1` = 0, `2` = 0, `3` = 0, `4` = 0, `5` = 1) + stan_pred_upper <- c(`1` = 1, `2` = 1, `3` = 1, `4` = 1, `5` = 1) + stan_pred_std <- + c(`1` = 0.211744742168102, `2` = 0.265130711714607, `3` = 0.209589904165081, + `4` = 0.198389410902796, `5` = 0.0446989708829856) expect_equivalent(prediction_parsnip$.pred_lower, stan_pred_lower) expect_equivalent(prediction_parsnip$.pred_upper, stan_pred_upper) expect_equivalent(prediction_parsnip$.std_error, stan_pred_std, tolerance = 0.1) From 837a55538df2017443e81b52fda07362d9d814bc Mon Sep 17 00:00:00 2001 From: topepo Date: Sat, 2 Mar 2019 21:16:14 -0500 Subject: [PATCH 30/34] remove ancillary files --- .Rbuildignore | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.Rbuildignore b/.Rbuildignore index 1bf63fb83..387dedcff 100644 --- a/.Rbuildignore +++ b/.Rbuildignore @@ -7,3 +7,6 @@ ^\.Rproj\.user$ ^.travis.yml$ ^R/README\.md$ +derby.log +^logs$ +^tests/testthat/logs$ \ No newline at end of file From 22407389969daa50701953383bc9ba3102e25090 Mon Sep 17 00:00:00 2001 From: topepo Date: Sat, 2 Mar 2019 21:41:01 -0500 Subject: [PATCH 31/34] avodi returning multiple logicals --- R/multinom_reg.R | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/R/multinom_reg.R b/R/multinom_reg.R index 33fc37918..de9d5938f 100644 --- a/R/multinom_reg.R +++ b/R/multinom_reg.R @@ -168,7 +168,7 @@ check_args.multinom_reg <- function(object) { args <- lapply(object$args, rlang::eval_tidy) - if (is.numeric(args$penalty) && args$penalty < 0) + if (all(is.numeric(args$penalty)) && any(args$penalty < 0)) stop("The amount of regularization should be >= 0", call. = FALSE) if (is.numeric(args$mixture) && (args$mixture < 0 | args$mixture > 1)) stop("The mixture proportion should be within [0,1]", call. = FALSE) From 90b220d930449ea4877817b1468519a2bd762ce2 Mon Sep 17 00:00:00 2001 From: topepo Date: Sat, 2 Mar 2019 22:03:09 -0500 Subject: [PATCH 32/34] back to computing probability results --- tests/testthat/test_svm_poly.R | 24 ++++++++++++------------ tests/testthat/test_svm_rbf.R | 22 +++++++++++----------- 2 files changed, 23 insertions(+), 23 deletions(-) diff --git a/tests/testthat/test_svm_poly.R b/tests/testthat/test_svm_poly.R index 8de5827c7..075c55b5a 100644 --- a/tests/testthat/test_svm_poly.R +++ b/tests/testthat/test_svm_poly.R @@ -245,19 +245,19 @@ test_that('svm poly classification probabilities', { ) expect_equal(cls_form$fit, cls_xy_form$fit) - # kern_probs <- - # predict(cls_form$fit, iris[ind, -5], type = "probabilities") %>% - # as_tibble() %>% - # setNames(c('.pred_setosa', '.pred_versicolor', '.pred_virginica')) - kern_probs <- - structure( - list( - .pred_setosa = c(0.982990083267231, 0.0167077303224448, 0.00930879923686657), - .pred_versicolor = c(0.00417116710624842, 0.946131931665357, 0.0015524073332013), - .pred_virginica = c(0.0128387496265202, 0.0371603380121978, 0.989138793429932)), - row.names = c(NA,-3L), - class = c("tbl_df", "tbl", "data.frame")) + predict(cls_form$fit, iris[ind, -5], type = "probabilities") %>% + as_tibble() %>% + setNames(c('.pred_setosa', '.pred_versicolor', '.pred_virginica')) + + # kern_probs <- + # structure( + # list( + # .pred_setosa = c(0.982990083267231, 0.0167077303224448, 0.00930879923686657), + # .pred_versicolor = c(0.00417116710624842, 0.946131931665357, 0.0015524073332013), + # .pred_virginica = c(0.0128387496265202, 0.0371603380121978, 0.989138793429932)), + # row.names = c(NA,-3L), + # class = c("tbl_df", "tbl", "data.frame")) parsnip_probs <- predict(cls_form, iris[ind, -5], type = "prob") expect_equal(as.data.frame(kern_probs), as.data.frame(parsnip_probs)) diff --git a/tests/testthat/test_svm_rbf.R b/tests/testthat/test_svm_rbf.R index b4ab329c3..f364b12f0 100644 --- a/tests/testthat/test_svm_rbf.R +++ b/tests/testthat/test_svm_rbf.R @@ -221,18 +221,18 @@ test_that('svm rbf classification probabilities', { ) expect_equal(cls_form$fit, cls_xy_form$fit) - # kern_probs <- - # predict(cls_form$fit, iris[ind, -5], type = "probabilities") %>% - # as_tibble() %>% - # setNames(c('.pred_setosa', '.pred_versicolor', '.pred_virginica')) - kern_probs <- - structure( - list( - .pred_setosa = c(0.985403715135807, 0.0158818274678279, 0.00633995479908973), - .pred_versicolor = c(0.00818691538722139, 0.359005663318986, 0.0173471664171275), - .pred_virginica = c(0.00640936947697121, 0.625112509213187, 0.976312878783783)), - row.names = c(NA,-3L), class = c("tbl_df", "tbl", "data.frame")) + predict(cls_form$fit, iris[ind, -5], type = "probabilities") %>% + as_tibble() %>% + setNames(c('.pred_setosa', '.pred_versicolor', '.pred_virginica')) + + # kern_probs <- + # structure( + # list( + # .pred_setosa = c(0.985403715135807, 0.0158818274678279, 0.00633995479908973), + # .pred_versicolor = c(0.00818691538722139, 0.359005663318986, 0.0173471664171275), + # .pred_virginica = c(0.00640936947697121, 0.625112509213187, 0.976312878783783)), + # row.names = c(NA,-3L), class = c("tbl_df", "tbl", "data.frame")) parsnip_probs <- predict(cls_form, iris[ind, -5], type = "prob") expect_equal(as.data.frame(kern_probs), as.data.frame(parsnip_probs)) From d63510aada0a497cad11896b8db806b3f0ae3662 Mon Sep 17 00:00:00 2001 From: topepo Date: Sat, 2 Mar 2019 22:20:46 -0500 Subject: [PATCH 33/34] added library calls --- tests/testthat/test_svm_poly.R | 1 + tests/testthat/test_svm_rbf.R | 1 + 2 files changed, 2 insertions(+) diff --git a/tests/testthat/test_svm_poly.R b/tests/testthat/test_svm_poly.R index 075c55b5a..50a69ebd8 100644 --- a/tests/testthat/test_svm_poly.R +++ b/tests/testthat/test_svm_poly.R @@ -245,6 +245,7 @@ test_that('svm poly classification probabilities', { ) expect_equal(cls_form$fit, cls_xy_form$fit) + library(kernlab) kern_probs <- predict(cls_form$fit, iris[ind, -5], type = "probabilities") %>% as_tibble() %>% diff --git a/tests/testthat/test_svm_rbf.R b/tests/testthat/test_svm_rbf.R index f364b12f0..50a3289e2 100644 --- a/tests/testthat/test_svm_rbf.R +++ b/tests/testthat/test_svm_rbf.R @@ -221,6 +221,7 @@ test_that('svm rbf classification probabilities', { ) expect_equal(cls_form$fit, cls_xy_form$fit) + library(kernlab) kern_probs <- predict(cls_form$fit, iris[ind, -5], type = "probabilities") %>% as_tibble() %>% From 1404357f8f47985836eb2c4309b7448eec45cf9c Mon Sep 17 00:00:00 2001 From: topepo Date: Sat, 2 Mar 2019 23:08:58 -0500 Subject: [PATCH 34/34] namespace the predict function --- tests/testthat/test_svm_poly.R | 2 +- tests/testthat/test_svm_rbf.R | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/testthat/test_svm_poly.R b/tests/testthat/test_svm_poly.R index 50a69ebd8..1835a3f5a 100644 --- a/tests/testthat/test_svm_poly.R +++ b/tests/testthat/test_svm_poly.R @@ -247,7 +247,7 @@ test_that('svm poly classification probabilities', { library(kernlab) kern_probs <- - predict(cls_form$fit, iris[ind, -5], type = "probabilities") %>% + kernlab::predict(cls_form$fit, iris[ind, -5], type = "probabilities") %>% as_tibble() %>% setNames(c('.pred_setosa', '.pred_versicolor', '.pred_virginica')) diff --git a/tests/testthat/test_svm_rbf.R b/tests/testthat/test_svm_rbf.R index 50a3289e2..ba78f284b 100644 --- a/tests/testthat/test_svm_rbf.R +++ b/tests/testthat/test_svm_rbf.R @@ -223,7 +223,7 @@ test_that('svm rbf classification probabilities', { library(kernlab) kern_probs <- - predict(cls_form$fit, iris[ind, -5], type = "probabilities") %>% + kernlab::predict(cls_form$fit, iris[ind, -5], type = "probabilities") %>% as_tibble() %>% setNames(c('.pred_setosa', '.pred_versicolor', '.pred_virginica'))