Skip to content

REF test_control to helper-objects #231

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Dec 1, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions tests/testthat/helper-objects.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
ctrl <- control_parsnip(verbosity = 1, catch = FALSE)
caught_ctrl <- control_parsnip(verbosity = 1, catch = TRUE)
quiet_ctrl <- control_parsnip(verbosity = 0, catch = TRUE)
5 changes: 1 addition & 4 deletions tests/testthat/test_boost_tree_C50.R
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ library(dplyr)
# ------------------------------------------------------------------------------

context("boosted tree execution with C5.0")
source("helper-objects.R")

data("lending_club")
lending_club <- head(lending_club, 200)
Expand All @@ -17,10 +18,6 @@ lc_basic <-
boost_tree(mode = "classification") %>%
set_engine("C5.0", bands = 2)

ctrl <- control_parsnip(verbosity = 1, catch = FALSE)
caught_ctrl <- control_parsnip(verbosity = 1, catch = TRUE)
quiet_ctrl <- control_parsnip(verbosity = 0, catch = TRUE)

# ------------------------------------------------------------------------------

test_that('C5.0 execution', {
Expand Down
5 changes: 1 addition & 4 deletions tests/testthat/test_boost_tree_spark.R
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,7 @@ library(dplyr)
# ------------------------------------------------------------------------------

context("boosted tree execution with spark")

ctrl <- control_parsnip(verbosity = 1, catch = FALSE)
caught_ctrl <- control_parsnip(verbosity = 1, catch = TRUE)
quiet_ctrl <- control_parsnip(verbosity = 0, catch = TRUE)
source("helper-objects.R")

# ------------------------------------------------------------------------------

Expand Down
9 changes: 1 addition & 8 deletions tests/testthat/test_boost_tree_xgboost.R
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,14 @@ library(parsnip)
# ------------------------------------------------------------------------------

context("boosted tree execution with xgboost")
source("helper-objects.R")

num_pred <- names(iris)[1:4]

iris_xgboost <-
boost_tree(trees = 2, mode = "classification") %>%
set_engine("xgboost")

ctrl <- control_parsnip(verbosity = 1, catch = FALSE)
caught_ctrl <- control_parsnip(verbosity = 1, catch = TRUE)
quiet_ctrl <- control_parsnip(verbosity = 0, catch = TRUE)

# ------------------------------------------------------------------------------

test_that('xgboost execution, classification', {
Expand Down Expand Up @@ -101,10 +98,6 @@ bad_rf_reg <-
boost_tree(mode = "regression") %>%
set_engine("xgboost", sampsize = -10)

ctrl <- list(verbosity = 1, catch = FALSE)
caught_ctrl <- list(verbosity = 1, catch = TRUE)
quiet_ctrl <- list(verbosity = 0, catch = TRUE)

test_that('xgboost execution, regression', {

skip_if_not_installed("xgboost")
Expand Down
5 changes: 1 addition & 4 deletions tests/testthat/test_linear_reg.R
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ library(tibble)

context("linear regression")
source("helpers.R")
source("helper-objects.R")

# ------------------------------------------------------------------------------

Expand Down Expand Up @@ -209,10 +210,6 @@ num_pred <- c("Sepal.Width", "Petal.Width", "Petal.Length")
iris_bad_form <- as.formula(Species ~ term)
iris_basic <- linear_reg() %>% set_engine("lm")

ctrl <- control_parsnip(verbosity = 1, catch = FALSE)
caught_ctrl <- control_parsnip(verbosity = 1, catch = TRUE)
quiet_ctrl <- control_parsnip(verbosity = 0, catch = TRUE)

# ------------------------------------------------------------------------------

test_that('lm execution', {
Expand Down
5 changes: 1 addition & 4 deletions tests/testthat/test_linear_reg_glmnet.R
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ library(tidyr)
# ------------------------------------------------------------------------------

context("linear regression execution with glmnet")
source("helper-objects.R")

num_pred <- c("Sepal.Width", "Petal.Width", "Petal.Length")
iris_bad_form <- as.formula(Species ~ term)
Expand All @@ -14,10 +15,6 @@ iris_basic <- linear_reg(penalty = .1, mixture = .3) %>%
no_lambda <- linear_reg(mixture = .3) %>%
set_engine("glmnet")

ctrl <- control_parsnip(verbosity = 1, catch = FALSE)
caught_ctrl <- control_parsnip(verbosity = 1, catch = TRUE)
quiet_ctrl <- control_parsnip(verbosity = 0, catch = TRUE)

# ------------------------------------------------------------------------------

test_that('glmnet execution', {
Expand Down
1 change: 1 addition & 0 deletions tests/testthat/test_linear_reg_keras.R
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ library(tibble)

context("keras linear regression")
source("helpers.R")
source("helper-objects.R")

# ------------------------------------------------------------------------------

Expand Down
5 changes: 1 addition & 4 deletions tests/testthat/test_linear_reg_spark.R
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,7 @@ library(dplyr)
# ------------------------------------------------------------------------------

context("linear regression execution with spark")

ctrl <- control_parsnip(verbosity = 1, catch = FALSE)
caught_ctrl <- control_parsnip(verbosity = 1, catch = TRUE)
quiet_ctrl <- control_parsnip(verbosity = 0, catch = TRUE)
source("helper-objects.R")

# ------------------------------------------------------------------------------

Expand Down
4 changes: 1 addition & 3 deletions tests/testthat/test_logistic_reg.R
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ library(tibble)

context("logistic regression")
source("helpers.R")
source("helper-objects.R")

# ------------------------------------------------------------------------------

Expand Down Expand Up @@ -219,9 +220,6 @@ lending_club <- head(lending_club, 200)
lc_form <- as.formula(Class ~ log(funded_amnt) + int_rate)
num_pred <- c("funded_amnt", "annual_inc", "num_il_tl")
lc_basic <- logistic_reg() %>% set_engine("glm")
ctrl <- control_parsnip(verbosity = 1, catch = FALSE)
caught_ctrl <- control_parsnip(verbosity = 1, catch = TRUE)
quiet_ctrl <- control_parsnip(verbosity = 0, catch = TRUE)

test_that('glm execution', {

Expand Down
5 changes: 1 addition & 4 deletions tests/testthat/test_logistic_reg_glmnet.R
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ library(tidyr)
# ------------------------------------------------------------------------------

context("logistic regression execution with glmnet")
source("helper-objects.R")

data("lending_club")
lending_club <- head(lending_club, 200)
Expand All @@ -15,10 +16,6 @@ num_pred <- c("funded_amnt", "annual_inc", "num_il_tl")
lc_bad_form <- as.formula(funded_amnt ~ term)
lc_basic <- logistic_reg() %>% set_engine("glmnet")

ctrl <- control_parsnip(verbosity = 1, catch = FALSE)
caught_ctrl <- control_parsnip(verbosity = 1, catch = TRUE)
quiet_ctrl <- control_parsnip(verbosity = 0, catch = TRUE)

# ------------------------------------------------------------------------------

test_that('glmnet execution', {
Expand Down
5 changes: 1 addition & 4 deletions tests/testthat/test_logistic_reg_spark.R
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,7 @@ library(dplyr)
# ------------------------------------------------------------------------------

context("logistic regression execution with spark")

ctrl <- control_parsnip(verbosity = 1, catch = FALSE)
caught_ctrl <- control_parsnip(verbosity = 1, catch = TRUE)
quiet_ctrl <- control_parsnip(verbosity = 0, catch = TRUE)
source("helper-objects.R")

# ------------------------------------------------------------------------------

Expand Down
1 change: 1 addition & 0 deletions tests/testthat/test_logistic_reg_stan.R
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ library(tibble)
# ------------------------------------------------------------------------------

context("execution tests for stan logistic regression")
source("helper-objects.R")

data("lending_club")
lending_club <- head(lending_club, 200)
Expand Down
5 changes: 1 addition & 4 deletions tests/testthat/test_mars.R
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ library(rlang)

context("mars tests")
source("helpers.R")
source("helper-objects.R")

# ------------------------------------------------------------------------------

Expand Down Expand Up @@ -124,10 +125,6 @@ num_pred <- c("Sepal.Width", "Petal.Width", "Petal.Length")
iris_bad_form <- as.formula(Species ~ term)
iris_basic <- mars(mode = "regression") %>% set_engine("earth")

ctrl <- control_parsnip(verbosity = 1, catch = FALSE)
caught_ctrl <- control_parsnip(verbosity = 1, catch = TRUE)
quiet_ctrl <- control_parsnip(verbosity = 0, catch = TRUE)

# ------------------------------------------------------------------------------

test_that('mars execution', {
Expand Down
9 changes: 1 addition & 8 deletions tests/testthat/test_mlp_keras.R
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,14 @@ library(tibble)
# ------------------------------------------------------------------------------

context("simple neural network execution with keras")
source("helper-objects.R")

num_pred <- names(iris)[1:4]

iris_keras <-
mlp(mode = "classification", hidden_units = 2, epochs = 10) %>%
set_engine("keras", verbose = 0)

ctrl <- control_parsnip(verbosity = 1, catch = FALSE)
caught_ctrl <- control_parsnip(verbosity = 1, catch = TRUE)
quiet_ctrl <- control_parsnip(verbosity = 0, catch = TRUE)

nn_dat <- read.csv("nnet_test.txt")

# ------------------------------------------------------------------------------
Expand Down Expand Up @@ -143,10 +140,6 @@ bad_keras_reg <-
mlp(mode = "regression") %>%
set_engine("keras", min.node.size = -10)

ctrl <- list(verbosity = 1, catch = FALSE)
caught_ctrl <- list(verbosity = 1, catch = TRUE)
quiet_ctrl <- list(verbosity = 0, catch = TRUE)

# ------------------------------------------------------------------------------


Expand Down
9 changes: 1 addition & 8 deletions tests/testthat/test_mlp_nnet.R
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,14 @@ library(parsnip)
# ------------------------------------------------------------------------------

context("simple neural network execution with nnet")
source("helper-objects.R")

num_pred <- names(iris)[1:4]

iris_nnet <-
mlp(mode = "classification", hidden_units = 5) %>%
set_engine("nnet")

ctrl <- control_parsnip(verbosity = 1, catch = FALSE)
caught_ctrl <- control_parsnip(verbosity = 1, catch = TRUE)
quiet_ctrl <- control_parsnip(verbosity = 0, catch = TRUE)

# ------------------------------------------------------------------------------

test_that('nnet execution, classification', {
Expand Down Expand Up @@ -94,10 +91,6 @@ bad_rf_reg <-
mlp(mode = "regression") %>%
set_engine("nnet", sampsize = -10)

ctrl <- list(verbosity = 1, catch = FALSE)
caught_ctrl <- list(verbosity = 1, catch = TRUE)
quiet_ctrl <- list(verbosity = 0, catch = TRUE)

# ------------------------------------------------------------------------------


Expand Down
5 changes: 1 addition & 4 deletions tests/testthat/test_multinom_reg_glmnet.R
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,7 @@ library(tibble)
# ------------------------------------------------------------------------------

context("multinom regression execution with glmnet")

ctrl <- control_parsnip(verbosity = 1, catch = FALSE)
caught_ctrl <- control_parsnip(verbosity = 1, catch = TRUE)
quiet_ctrl <- control_parsnip(verbosity = 0, catch = TRUE)
source("helper-objects.R")

rows <- c(1, 51, 101)

Expand Down
5 changes: 1 addition & 4 deletions tests/testthat/test_multinom_reg_spark.R
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,7 @@ library(dplyr)
# ------------------------------------------------------------------------------

context("multinomial regression execution with spark")

ctrl <- control_parsnip(verbosity = 1, catch = FALSE)
caught_ctrl <- control_parsnip(verbosity = 1, catch = TRUE)
quiet_ctrl <- control_parsnip(verbosity = 0, catch = TRUE)
source("helper-objects.R")

# ------------------------------------------------------------------------------

Expand Down
5 changes: 1 addition & 4 deletions tests/testthat/test_nearest_neighbor_kknn.R
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ library(rlang)
# ------------------------------------------------------------------------------

context("nearest neighbor execution with kknn")
source("helper-objects.R")

num_pred <- c("Sepal.Width", "Petal.Width", "Petal.Length")
iris_bad_form <- as.formula(Species ~ term)
Expand All @@ -13,10 +14,6 @@ iris_basic <- nearest_neighbor(mode = "classification",
weight_func = "triangular") %>%
set_engine("kknn")

ctrl <- control_parsnip(verbosity = 1, catch = FALSE)
caught_ctrl <- control_parsnip(verbosity = 1, catch = TRUE)
quiet_ctrl <- control_parsnip(verbosity = 0, catch = TRUE)

# ------------------------------------------------------------------------------

test_that('kknn execution', {
Expand Down
9 changes: 1 addition & 8 deletions tests/testthat/test_rand_forest_randomForest.R
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ library(tibble)
# ------------------------------------------------------------------------------

context("random forest execution with randomForest")
source("helper-objects.R")

# ------------------------------------------------------------------------------

Expand All @@ -17,10 +18,6 @@ lc_basic <- rand_forest(mode = "classification") %>%
bad_rf_cls <- rand_forest(mode = "classification") %>%
set_engine("randomForest", sampsize = -10)

ctrl <- control_parsnip(verbosity = 1, catch = FALSE)
caught_ctrl <- control_parsnip(verbosity = 1, catch = TRUE)
quiet_ctrl <- control_parsnip(verbosity = 0, catch = TRUE)

# ------------------------------------------------------------------------------

test_that('randomForest classification execution', {
Expand Down Expand Up @@ -156,10 +153,6 @@ bad_ranger_reg <- rand_forest(mode = "regression") %>%
bad_rf_reg <- rand_forest(mode = "regression") %>%
set_engine("randomForest", sampsize = -10)

ctrl <- list(verbosity = 1, catch = FALSE)
caught_ctrl <- list(verbosity = 1, catch = TRUE)
quiet_ctrl <- list(verbosity = 0, catch = TRUE)

# ------------------------------------------------------------------------------

test_that('randomForest regression execution', {
Expand Down
9 changes: 1 addition & 8 deletions tests/testthat/test_rand_forest_ranger.R
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ library(rlang)
# ------------------------------------------------------------------------------

context("random forest execution with ranger")
source("helper-objects.R")

# ------------------------------------------------------------------------------

Expand All @@ -19,10 +20,6 @@ lc_ranger <- rand_forest(mode = "classification") %>% set_engine("ranger", seed
bad_ranger_cls <- rand_forest(mode = "classification") %>% set_engine("ranger", replace = "bad")
bad_rf_cls <- rand_forest(mode = "classification") %>% set_engine("ranger", sampsize = -10)

ctrl <- control_parsnip(verbosity = 1, catch = FALSE)
caught_ctrl <- control_parsnip(verbosity = 1, catch = TRUE)
quiet_ctrl <- control_parsnip(verbosity = 0, catch = TRUE)

# ------------------------------------------------------------------------------

test_that('ranger classification execution', {
Expand Down Expand Up @@ -178,10 +175,6 @@ car_basic <- rand_forest(mode = "regression") %>% set_engine("ranger")
bad_ranger_reg <- rand_forest(mode = "regression") %>% set_engine("ranger", replace = "bad")
bad_rf_reg <- rand_forest(mode = "regression") %>% set_engine("ranger", sampsize = -10)

ctrl <- list(verbosity = 1, catch = FALSE)
caught_ctrl <- list(verbosity = 1, catch = TRUE)
quiet_ctrl <- list(verbosity = 0, catch = TRUE)

# ------------------------------------------------------------------------------

test_that('ranger regression execution', {
Expand Down
5 changes: 1 addition & 4 deletions tests/testthat/test_rand_forest_spark.R
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,7 @@ library(dplyr)
# ------------------------------------------------------------------------------

context("random forest execution with spark")

ctrl <- control_parsnip(verbosity = 1, catch = FALSE)
caught_ctrl <- control_parsnip(verbosity = 1, catch = TRUE)
quiet_ctrl <- control_parsnip(verbosity = 0, catch = TRUE)
source("helper-objects.R")

# ------------------------------------------------------------------------------

Expand Down
5 changes: 2 additions & 3 deletions tests/testthat/test_surv_reg_flexsurv.R
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,12 @@ library(tibble)

# ------------------------------------------------------------------------------

source("helper-objects.R")

basic_form <- Surv(time, status) ~ age
complete_form <- Surv(time) ~ age

surv_basic <- surv_reg() %>% set_engine("flexsurv")
ctrl <- control_parsnip(verbosity = 1, catch = FALSE)
caught_ctrl <- control_parsnip(verbosity = 1, catch = TRUE)
quiet_ctrl <- control_parsnip(verbosity = 0, catch = TRUE)

# ------------------------------------------------------------------------------

Expand Down
Loading