From 132abc965910626ad3cfe6b602a1451cf7b944a4 Mon Sep 17 00:00:00 2001 From: simonpcouch Date: Fri, 5 Apr 2024 10:26:04 -0500 Subject: [PATCH] test tunable output --- tests/testthat/_snaps/tunable.md | 410 +++++++++++++++++++++++++++++++ tests/testthat/test-tunable.R | 105 ++++++++ 2 files changed, 515 insertions(+) create mode 100644 tests/testthat/_snaps/tunable.md create mode 100644 tests/testthat/test-tunable.R diff --git a/tests/testthat/_snaps/tunable.md b/tests/testthat/_snaps/tunable.md new file mode 100644 index 000000000..e75281f08 --- /dev/null +++ b/tests/testthat/_snaps/tunable.md @@ -0,0 +1,410 @@ +# tunable.linear_reg() + + Code + tunable(spec) + Output + # A tibble: 0 x 5 + # i 5 variables: name , call_info , source , component , + # component_id + +--- + + Code + tunable(spec %>% set_engine("lm")) + Output + # A tibble: 0 x 5 + # i 5 variables: name , call_info , source , component , + # component_id + +--- + + Code + tunable(spec %>% set_engine("glmnet")) + Output + # A tibble: 2 x 5 + name call_info source component component_id + + 1 penalty model_spec linear_reg main + 2 mixture model_spec linear_reg main + +--- + + Code + tunable(spec %>% set_engine("brulee")) + Output + # A tibble: 2 x 5 + name call_info source component component_id + + 1 penalty model_spec linear_reg main + 2 mixture model_spec linear_reg main + +# tunable.logistic_reg() + + Code + tunable(spec) + Output + # A tibble: 0 x 5 + # i 5 variables: name , call_info , source , component , + # component_id + +--- + + Code + tunable(spec %>% set_engine("glm")) + Output + # A tibble: 0 x 5 + # i 5 variables: name , call_info , source , component , + # component_id + +--- + + Code + tunable(spec %>% set_engine("glmnet")) + Output + # A tibble: 2 x 5 + name call_info source component component_id + + 1 penalty model_spec logistic_reg main + 2 mixture model_spec logistic_reg main + +--- + + Code + tunable(spec %>% set_engine("brulee")) + Output + # A tibble: 2 x 5 + name call_info source component component_id + + 1 penalty model_spec logistic_reg main + 2 mixture model_spec logistic_reg main + +# tunable.multinom_reg() + + Code + tunable(spec) + Output + # A tibble: 1 x 5 + name call_info source component component_id + + 1 penalty model_spec multinom_reg main + +--- + + Code + tunable(spec %>% set_engine("glmnet")) + Output + # A tibble: 2 x 5 + name call_info source component component_id + + 1 penalty model_spec multinom_reg main + 2 mixture model_spec multinom_reg main + +--- + + Code + tunable(spec %>% set_engine("spark")) + Output + # A tibble: 2 x 5 + name call_info source component component_id + + 1 penalty model_spec multinom_reg main + 2 mixture model_spec multinom_reg main + +--- + + Code + tunable(spec %>% set_engine("keras")) + Output + # A tibble: 1 x 5 + name call_info source component component_id + + 1 penalty model_spec multinom_reg main + +--- + + Code + tunable(spec %>% set_engine("nnet")) + Output + # A tibble: 1 x 5 + name call_info source component component_id + + 1 penalty model_spec multinom_reg main + +--- + + Code + tunable(spec %>% set_engine("brulee")) + Output + # A tibble: 2 x 5 + name call_info source component component_id + + 1 penalty model_spec multinom_reg main + 2 mixture model_spec multinom_reg main + +# tunable.boost_tree() + + Code + tunable(spec) + Output + # A tibble: 8 x 5 + name call_info source component component_id + + 1 tree_depth model_spec boost_tree main + 2 trees model_spec boost_tree main + 3 learn_rate model_spec boost_tree main + 4 mtry model_spec boost_tree main + 5 min_n model_spec boost_tree main + 6 loss_reduction model_spec boost_tree main + 7 sample_size model_spec boost_tree main + 8 stop_iter model_spec boost_tree main + +--- + + Code + tunable(spec %>% set_engine("xgboost")) + Output + # A tibble: 8 x 5 + name call_info source component component_id + + 1 tree_depth model_spec boost_tree main + 2 trees model_spec boost_tree main + 3 learn_rate model_spec boost_tree main + 4 mtry model_spec boost_tree main + 5 min_n model_spec boost_tree main + 6 loss_reduction model_spec boost_tree main + 7 sample_size model_spec boost_tree main + 8 stop_iter model_spec boost_tree main + +--- + + Code + tunable(spec %>% set_engine("C5.0")) + Output + # A tibble: 3 x 5 + name call_info source component component_id + + 1 trees model_spec boost_tree main + 2 min_n model_spec boost_tree main + 3 sample_size model_spec boost_tree main + +--- + + Code + tunable(spec %>% set_engine("spark")) + Output + # A tibble: 7 x 5 + name call_info source component component_id + + 1 tree_depth model_spec boost_tree main + 2 trees model_spec boost_tree main + 3 learn_rate model_spec boost_tree main + 4 mtry model_spec boost_tree main + 5 min_n model_spec boost_tree main + 6 loss_reduction model_spec boost_tree main + 7 sample_size model_spec boost_tree main + +# tunable.rand_forest() + + Code + tunable(spec) + Output + # A tibble: 3 x 5 + name call_info source component component_id + + 1 mtry model_spec rand_forest main + 2 trees model_spec rand_forest main + 3 min_n model_spec rand_forest main + +--- + + Code + tunable(spec %>% set_engine("ranger")) + Output + # A tibble: 3 x 5 + name call_info source component component_id + + 1 mtry model_spec rand_forest main + 2 trees model_spec rand_forest main + 3 min_n model_spec rand_forest main + +--- + + Code + tunable(spec %>% set_engine("randomForest")) + Output + # A tibble: 3 x 5 + name call_info source component component_id + + 1 mtry model_spec rand_forest main + 2 trees model_spec rand_forest main + 3 min_n model_spec rand_forest main + +--- + + Code + tunable(spec %>% set_engine("spark")) + Output + # A tibble: 3 x 5 + name call_info source component component_id + + 1 mtry model_spec rand_forest main + 2 trees model_spec rand_forest main + 3 min_n model_spec rand_forest main + +# tunable.mars() + + Code + tunable(spec) + Output + # A tibble: 3 x 5 + name call_info source component component_id + + 1 num_terms model_spec mars main + 2 prod_degree model_spec mars main + 3 prune_method model_spec mars main + +--- + + Code + tunable(spec %>% set_engine("earth")) + Output + # A tibble: 3 x 5 + name call_info source component component_id + + 1 num_terms model_spec mars main + 2 prod_degree model_spec mars main + 3 prune_method model_spec mars main + +# tunable.decision_tree() + + Code + tunable(spec) + Output + # A tibble: 3 x 5 + name call_info source component component_id + + 1 tree_depth model_spec decision_tree main + 2 min_n model_spec decision_tree main + 3 cost_complexity model_spec decision_tree main + +--- + + Code + tunable(spec %>% set_engine("rpart")) + Output + # A tibble: 3 x 5 + name call_info source component component_id + + 1 tree_depth model_spec decision_tree main + 2 min_n model_spec decision_tree main + 3 cost_complexity model_spec decision_tree main + +--- + + Code + tunable(spec %>% set_engine("C5.0")) + Output + # A tibble: 1 x 5 + name call_info source component component_id + + 1 min_n model_spec decision_tree main + +--- + + Code + tunable(spec %>% set_engine("spark")) + Output + # A tibble: 2 x 5 + name call_info source component component_id + + 1 tree_depth model_spec decision_tree main + 2 min_n model_spec decision_tree main + +# tunable.svm_poly() + + Code + tunable(spec) + Output + # A tibble: 4 x 5 + name call_info source component component_id + + 1 cost model_spec svm_poly main + 2 degree model_spec svm_poly main + 3 scale_factor model_spec svm_poly main + 4 margin model_spec svm_poly main + +--- + + Code + tunable(spec %>% set_engine("kernlab")) + Output + # A tibble: 4 x 5 + name call_info source component component_id + + 1 cost model_spec svm_poly main + 2 degree model_spec svm_poly main + 3 scale_factor model_spec svm_poly main + 4 margin model_spec svm_poly main + +# tunable.mlp() + + Code + tunable(spec) + Output + # A tibble: 3 x 5 + name call_info source component component_id + + 1 hidden_units model_spec mlp main + 2 penalty model_spec mlp main + 3 epochs model_spec mlp main + +--- + + Code + tunable(spec %>% set_engine("keras")) + Output + # A tibble: 5 x 5 + name call_info source component component_id + + 1 hidden_units model_spec mlp main + 2 penalty model_spec mlp main + 3 dropout model_spec mlp main + 4 epochs model_spec mlp main + 5 activation model_spec mlp main + +--- + + Code + tunable(spec %>% set_engine("nnet")) + Output + # A tibble: 3 x 5 + name call_info source component component_id + + 1 hidden_units model_spec mlp main + 2 penalty model_spec mlp main + 3 epochs model_spec mlp main + +--- + + Code + tunable(spec %>% set_engine("brulee")) + Output + # A tibble: 6 x 5 + name call_info source component component_id + + 1 hidden_units model_spec mlp main + 2 penalty model_spec mlp main + 3 epochs model_spec mlp main + 4 dropout model_spec mlp main + 5 learn_rate model_spec mlp main + 6 activation model_spec mlp main + +# tunable.survival_reg() + + Code + tunable(spec) + Output + # A tibble: 0 x 5 + # i 5 variables: name , call_info , source , component , + # component_id + diff --git a/tests/testthat/test-tunable.R b/tests/testthat/test-tunable.R new file mode 100644 index 000000000..8f799594c --- /dev/null +++ b/tests/testthat/test-tunable.R @@ -0,0 +1,105 @@ +# general pattern, for each tunable method: +# define `spec`, run `show_engines()` with only parsnip loaded, +# snapshot test `tunable()` output for each unique engine. +# +# note that, as implemented, parsnip can return `tunable()` information +# for engines that it cannot fit without first loading an extension package. +# +# the specific contents of call_info are just hard-coded tibbles in the +# source, so snapshot testing only for their presence rather than contents. + +test_that("tunable.linear_reg()", { + spec <- linear_reg() + expect_snapshot(tunable(spec)) + expect_snapshot(tunable(spec %>% set_engine("lm"))) + expect_snapshot(tunable(spec %>% set_engine("glmnet"))) + expect_snapshot(tunable(spec %>% set_engine("brulee"))) + + # tests for call_info in tidymodels/extratests +}) + +test_that("tunable.logistic_reg()", { + spec <- logistic_reg() + expect_snapshot(tunable(spec)) + expect_snapshot(tunable(spec %>% set_engine("glm"))) + expect_snapshot(tunable(spec %>% set_engine("glmnet"))) + expect_snapshot(tunable(spec %>% set_engine("brulee"))) + + # tests for call_info and additional engines in tidymodels/extratests +}) + +test_that("tunable.multinom_reg()", { + spec <- multinom_reg() + expect_snapshot(tunable(spec)) + expect_snapshot(tunable(spec %>% set_engine("glmnet"))) + expect_snapshot(tunable(spec %>% set_engine("spark"))) + expect_snapshot(tunable(spec %>% set_engine("keras"))) + expect_snapshot(tunable(spec %>% set_engine("nnet"))) + expect_snapshot(tunable(spec %>% set_engine("brulee"))) + + # tests for call_info and additional engines in tidymodels/extratests +}) + +test_that("tunable.boost_tree()", { + spec <- boost_tree() + expect_snapshot(tunable(spec)) + expect_snapshot(tunable(spec %>% set_engine("xgboost"))) + expect_snapshot(tunable(spec %>% set_engine("C5.0"))) + expect_snapshot(tunable(spec %>% set_engine("spark"))) + + # tests for call_info and additional engines in tidymodels/extratests +}) + +test_that("tunable.rand_forest()", { + spec <- rand_forest() + expect_snapshot(tunable(spec)) + expect_snapshot(tunable(spec %>% set_engine("ranger"))) + expect_snapshot(tunable(spec %>% set_engine("randomForest"))) + expect_snapshot(tunable(spec %>% set_engine("spark"))) + + # tests for call_info and additional engines in tidymodels/extratests +}) + +test_that("tunable.mars()", { + spec <- mars() + expect_snapshot(tunable(spec)) + expect_snapshot(tunable(spec %>% set_engine("earth"))) + + # tests for call_info and additional engines in tidymodels/extratests +}) + +test_that("tunable.decision_tree()", { + spec <- decision_tree() + expect_snapshot(tunable(spec)) + expect_snapshot(tunable(spec %>% set_engine("rpart"))) + expect_snapshot(tunable(spec %>% set_engine("C5.0"))) + expect_snapshot(tunable(spec %>% set_engine("spark"))) + + # tests for call_info and additional engines in tidymodels/extratests +}) + +test_that("tunable.svm_poly()", { + spec <- svm_poly() + expect_snapshot(tunable(spec)) + expect_snapshot(tunable(spec %>% set_engine("kernlab"))) + + # tests for call_info and additional engines in tidymodels/extratests +}) + +test_that("tunable.mlp()", { + spec <- mlp() + expect_snapshot(tunable(spec)) + expect_snapshot(tunable(spec %>% set_engine("keras"))) + expect_snapshot(tunable(spec %>% set_engine("nnet"))) + expect_snapshot(tunable(spec %>% set_engine("brulee"))) + + # tests for call_info and additional engines in tidymodels/extratests +}) + + +test_that("tunable.survival_reg()", { + spec <- survival_reg() + expect_snapshot(tunable(spec)) + + # tests for call_info and additional engines in tidymodels/extratests +})