Skip to content

Commit 6e8106e

Browse files
committed
demonstrate 1104
1 parent 132abc9 commit 6e8106e

File tree

2 files changed

+162
-10
lines changed

2 files changed

+162
-10
lines changed

tests/testthat/_snaps/tunable.md

Lines changed: 141 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,18 @@
3838
1 penalty <named list [2]> model_spec linear_reg main
3939
2 mixture <named list [2]> model_spec linear_reg main
4040

41+
---
42+
43+
Code
44+
tunable(spec %>% set_engine("glmnet", dfmax = tune()))
45+
Output
46+
# A tibble: 3 x 5
47+
name call_info source component component_id
48+
<chr> <list> <chr> <chr> <chr>
49+
1 penalty <named list [2]> model_spec linear_reg main
50+
2 mixture <named list [3]> model_spec linear_reg main
51+
3 dfmax <NULL> model_spec linear_reg engine
52+
4153
# tunable.logistic_reg()
4254

4355
Code
@@ -78,6 +90,18 @@
7890
1 penalty <named list [2]> model_spec logistic_reg main
7991
2 mixture <named list [2]> model_spec logistic_reg main
8092

93+
---
94+
95+
Code
96+
tunable(spec %>% set_engine("glmnet", dfmax = tune()))
97+
Output
98+
# A tibble: 3 x 5
99+
name call_info source component component_id
100+
<chr> <list> <chr> <chr> <chr>
101+
1 penalty <named list [2]> model_spec logistic_reg main
102+
2 mixture <named list [3]> model_spec logistic_reg main
103+
3 dfmax <NULL> model_spec logistic_reg engine
104+
81105
# tunable.multinom_reg()
82106

83107
Code
@@ -141,6 +165,18 @@
141165
1 penalty <named list [2]> model_spec multinom_reg main
142166
2 mixture <named list [2]> model_spec multinom_reg main
143167

168+
---
169+
170+
Code
171+
tunable(spec %>% set_engine("glmnet", dfmax = tune()))
172+
Output
173+
# A tibble: 3 x 5
174+
name call_info source component component_id
175+
<chr> <list> <chr> <chr> <chr>
176+
1 penalty <named list [2]> model_spec multinom_reg main
177+
2 mixture <named list [2]> model_spec multinom_reg main
178+
3 dfmax <NULL> model_spec multinom_reg engine
179+
144180
# tunable.boost_tree()
145181

146182
Code
@@ -203,6 +239,24 @@
203239
6 loss_reduction <named list [2]> model_spec boost_tree main
204240
7 sample_size <named list [2]> model_spec boost_tree main
205241

242+
---
243+
244+
Code
245+
tunable(spec %>% set_engine("xgboost", feval = tune()))
246+
Output
247+
# A tibble: 9 x 5
248+
name call_info source component component_id
249+
<chr> <list> <chr> <chr> <chr>
250+
1 tree_depth <named list [2]> model_spec boost_tree main
251+
2 trees <named list [2]> model_spec boost_tree main
252+
3 learn_rate <named list [3]> model_spec boost_tree main
253+
4 mtry <named list [2]> model_spec boost_tree main
254+
5 min_n <named list [2]> model_spec boost_tree main
255+
6 loss_reduction <named list [2]> model_spec boost_tree main
256+
7 sample_size <named list [2]> model_spec boost_tree main
257+
8 stop_iter <named list [2]> model_spec boost_tree main
258+
9 feval <NULL> model_spec boost_tree engine
259+
206260
# tunable.rand_forest()
207261

208262
Code
@@ -251,6 +305,19 @@
251305
2 trees <named list [2]> model_spec rand_forest main
252306
3 min_n <named list [2]> model_spec rand_forest main
253307

308+
---
309+
310+
Code
311+
tunable(spec %>% set_engine("ranger", min.bucket = tune()))
312+
Output
313+
# A tibble: 4 x 5
314+
name call_info source component component_id
315+
<chr> <list> <chr> <chr> <chr>
316+
1 mtry <named list [2]> model_spec rand_forest main
317+
2 trees <named list [2]> model_spec rand_forest main
318+
3 min_n <named list [2]> model_spec rand_forest main
319+
4 min.bucket <NULL> model_spec rand_forest engine
320+
254321
# tunable.mars()
255322

256323
Code
@@ -275,6 +342,19 @@
275342
2 prod_degree <named list [2]> model_spec mars main
276343
3 prune_method <named list [2]> model_spec mars main
277344

345+
---
346+
347+
Code
348+
tunable(spec %>% set_engine("earth", minspan = tune()))
349+
Output
350+
# A tibble: 4 x 5
351+
name call_info source component component_id
352+
<chr> <list> <chr> <chr> <chr>
353+
1 num_terms <named list [3]> model_spec mars main
354+
2 prod_degree <named list [2]> model_spec mars main
355+
3 prune_method <named list [2]> model_spec mars main
356+
4 minspan <NULL> model_spec mars engine
357+
278358
# tunable.decision_tree()
279359

280360
Code
@@ -320,6 +400,19 @@
320400
1 tree_depth <named list [2]> model_spec decision_tree main
321401
2 min_n <named list [2]> model_spec decision_tree main
322402

403+
---
404+
405+
Code
406+
tunable(spec %>% set_engine("rpart", parms = tune()))
407+
Output
408+
# A tibble: 4 x 5
409+
name call_info source component component_id
410+
<chr> <list> <chr> <chr> <chr>
411+
1 tree_depth <named list [2]> model_spec decision_tree main
412+
2 min_n <named list [2]> model_spec decision_tree main
413+
3 cost_complexity <named list [2]> model_spec decision_tree main
414+
4 parms <NULL> model_spec decision_tree engine
415+
323416
# tunable.svm_poly()
324417

325418
Code
@@ -346,6 +439,20 @@
346439
3 scale_factor <named list [2]> model_spec svm_poly main
347440
4 margin <named list [2]> model_spec svm_poly main
348441

442+
---
443+
444+
Code
445+
tunable(spec %>% set_engine("kernlab", tol = tune()))
446+
Output
447+
# A tibble: 5 x 5
448+
name call_info source component component_id
449+
<chr> <list> <chr> <chr> <chr>
450+
1 cost <named list [3]> model_spec svm_poly main
451+
2 degree <named list [3]> model_spec svm_poly main
452+
3 scale_factor <named list [2]> model_spec svm_poly main
453+
4 margin <named list [2]> model_spec svm_poly main
454+
5 tol <NULL> model_spec svm_poly engine
455+
349456
# tunable.mlp()
350457

351458
Code
@@ -399,6 +506,21 @@
399506
5 learn_rate <named list [3]> model_spec mlp main
400507
6 activation <named list [3]> model_spec mlp main
401508

509+
---
510+
511+
Code
512+
tunable(spec %>% set_engine("keras", ragged = tune()))
513+
Output
514+
# A tibble: 6 x 5
515+
name call_info source component component_id
516+
<chr> <list> <chr> <chr> <chr>
517+
1 hidden_units <named list [2]> model_spec mlp main
518+
2 penalty <named list [2]> model_spec mlp main
519+
3 dropout <named list [2]> model_spec mlp main
520+
4 epochs <named list [2]> model_spec mlp main
521+
5 activation <named list [2]> model_spec mlp main
522+
6 ragged <NULL> model_spec mlp engine
523+
402524
# tunable.survival_reg()
403525

404526
Code
@@ -408,3 +530,22 @@
408530
# i 5 variables: name <chr>, call_info <list>, source <chr>, component <chr>,
409531
# component_id <chr>
410532

533+
---
534+
535+
Code
536+
tunable(spec %>% set_engine("survival"))
537+
Output
538+
# A tibble: 0 x 5
539+
# i 5 variables: name <chr>, call_info <list>, source <chr>, component <chr>,
540+
# component_id <chr>
541+
542+
---
543+
544+
Code
545+
tunable(spec %>% set_engine("survival", parms = tune()))
546+
Output
547+
# A tibble: 1 x 5
548+
name call_info source component component_id
549+
<chr> <list> <chr> <chr> <chr>
550+
1 parms <NULL> model_spec survival_reg engine
551+

tests/testthat/test-tunable.R

Lines changed: 21 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@ test_that("tunable.linear_reg()", {
1515
expect_snapshot(tunable(spec %>% set_engine("glmnet")))
1616
expect_snapshot(tunable(spec %>% set_engine("brulee")))
1717

18-
# tests for call_info in tidymodels/extratests
18+
# don't include rows for non-tunable args marked with tune() (#1104)
19+
expect_snapshot(tunable(spec %>% set_engine("glmnet", dfmax = tune())))
1920
})
2021

2122
test_that("tunable.logistic_reg()", {
@@ -25,7 +26,8 @@ test_that("tunable.logistic_reg()", {
2526
expect_snapshot(tunable(spec %>% set_engine("glmnet")))
2627
expect_snapshot(tunable(spec %>% set_engine("brulee")))
2728

28-
# tests for call_info and additional engines in tidymodels/extratests
29+
# don't include rows for non-tunable args marked with tune() (#1104)
30+
expect_snapshot(tunable(spec %>% set_engine("glmnet", dfmax = tune())))
2931
})
3032

3133
test_that("tunable.multinom_reg()", {
@@ -37,7 +39,8 @@ test_that("tunable.multinom_reg()", {
3739
expect_snapshot(tunable(spec %>% set_engine("nnet")))
3840
expect_snapshot(tunable(spec %>% set_engine("brulee")))
3941

40-
# tests for call_info and additional engines in tidymodels/extratests
42+
# don't include rows for non-tunable args marked with tune() (#1104)
43+
expect_snapshot(tunable(spec %>% set_engine("glmnet", dfmax = tune())))
4144
})
4245

4346
test_that("tunable.boost_tree()", {
@@ -47,7 +50,8 @@ test_that("tunable.boost_tree()", {
4750
expect_snapshot(tunable(spec %>% set_engine("C5.0")))
4851
expect_snapshot(tunable(spec %>% set_engine("spark")))
4952

50-
# tests for call_info and additional engines in tidymodels/extratests
53+
# don't include rows for non-tunable args marked with tune() (#1104)
54+
expect_snapshot(tunable(spec %>% set_engine("xgboost", feval = tune())))
5155
})
5256

5357
test_that("tunable.rand_forest()", {
@@ -57,15 +61,17 @@ test_that("tunable.rand_forest()", {
5761
expect_snapshot(tunable(spec %>% set_engine("randomForest")))
5862
expect_snapshot(tunable(spec %>% set_engine("spark")))
5963

60-
# tests for call_info and additional engines in tidymodels/extratests
64+
# don't include rows for non-tunable args marked with tune() (#1104)
65+
expect_snapshot(tunable(spec %>% set_engine("ranger", min.bucket = tune())))
6166
})
6267

6368
test_that("tunable.mars()", {
6469
spec <- mars()
6570
expect_snapshot(tunable(spec))
6671
expect_snapshot(tunable(spec %>% set_engine("earth")))
6772

68-
# tests for call_info and additional engines in tidymodels/extratests
73+
# don't include rows for non-tunable args marked with tune() (#1104)
74+
expect_snapshot(tunable(spec %>% set_engine("earth", minspan = tune())))
6975
})
7076

7177
test_that("tunable.decision_tree()", {
@@ -75,15 +81,17 @@ test_that("tunable.decision_tree()", {
7581
expect_snapshot(tunable(spec %>% set_engine("C5.0")))
7682
expect_snapshot(tunable(spec %>% set_engine("spark")))
7783

78-
# tests for call_info and additional engines in tidymodels/extratests
84+
# don't include rows for non-tunable args marked with tune() (#1104)
85+
expect_snapshot(tunable(spec %>% set_engine("rpart", parms = tune())))
7986
})
8087

8188
test_that("tunable.svm_poly()", {
8289
spec <- svm_poly()
8390
expect_snapshot(tunable(spec))
8491
expect_snapshot(tunable(spec %>% set_engine("kernlab")))
8592

86-
# tests for call_info and additional engines in tidymodels/extratests
93+
# don't include rows for non-tunable args marked with tune() (#1104)
94+
expect_snapshot(tunable(spec %>% set_engine("kernlab", tol = tune())))
8795
})
8896

8997
test_that("tunable.mlp()", {
@@ -93,13 +101,16 @@ test_that("tunable.mlp()", {
93101
expect_snapshot(tunable(spec %>% set_engine("nnet")))
94102
expect_snapshot(tunable(spec %>% set_engine("brulee")))
95103

96-
# tests for call_info and additional engines in tidymodels/extratests
104+
# don't include rows for non-tunable args marked with tune() (#1104)
105+
expect_snapshot(tunable(spec %>% set_engine("keras", ragged = tune())))
97106
})
98107

99108

100109
test_that("tunable.survival_reg()", {
101110
spec <- survival_reg()
102111
expect_snapshot(tunable(spec))
112+
expect_snapshot(tunable(spec %>% set_engine("survival")))
103113

104-
# tests for call_info and additional engines in tidymodels/extratests
114+
# don't include rows for non-tunable args marked with tune() (#1104)
115+
expect_snapshot(tunable(spec %>% set_engine("survival", parms = tune())))
105116
})

0 commit comments

Comments
 (0)