Skip to content

Commit 083fd9a

Browse files
simonpcouchjuliasilgetopepo
authored
transition update internals (#704)
* `update_dot_check` -> `update_engine_parameters` * test `mars`-specific updating + tuning engine args * simplify engine params test no need to snapshot the `print.parameters` method: it may change soon, and some extension packages aren't using 3e yet * bump to new dev version this way, we can `Remotes` a specific parsnip version before package releases * refactor `update` methods The process: * put together a `update_spec` helper that does most all of the work that the `update` methods do * for each update method: + drop in the `update_spec` template + update it’s `cls` argument to match the same `new_model_spec` argument + if the `update` method doesn’t take a parameters argument, set it to NULL in `update_spec` + delete remaining code besides the `args` `enquo`ting lines Push before updating any of the tests to make sure that checks pass on the previous tests too. * bug fix in `update_engine_parameters` `fresh` was ignored and engine arguments propagated through `update` * refresh `update` unit tests transition most tests to `test_update` and test more thoroughly with one example. for each update method test, pass both a model and engine argument, and then `update` both of them to `tune()` (with some exceptions depending on available arguments). * re`document` for `fresh` arg * Fix possibly confusing typo in comment (named vs. name) * note `update()` bug fix in NEWS * Delete test_svm_liquidsvm.R Co-authored-by: Julia Silge <[email protected]> Co-authored-by: Max Kuhn <[email protected]>
1 parent 15d38ca commit 083fd9a

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

67 files changed

+661
-1949
lines changed

DESCRIPTION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Package: parsnip
22
Title: A Common API to Modeling and Analysis Functions
3-
Version: 0.2.1.9001
3+
Version: 0.2.1.9002
44
Authors@R: c(
55
person("Max", "Kuhn", , "[email protected]", role = c("aut", "cre")),
66
person("Davis", "Vaughan", , "[email protected]", role = "aut"),

NAMESPACE

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -295,6 +295,7 @@ export(update_dot_check)
295295
export(update_engine_parameters)
296296
export(update_main_parameters)
297297
export(update_model_info_file)
298+
export(update_spec)
298299
export(varying)
299300
export(varying_args)
300301
export(xgb_predict)

NEWS.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
* Exported `xgb_predict()` which wraps xgboost's `predict()` method for use with parsnip extension packages (#688).
88

9-
## Bug fixes
9+
* Fixed bug where previously set engine arguments would propagate through `update()` methods despite `fresh = TRUE` (#704).
1010

1111
* An inconsistency for probability type predictions for two-class GAM models was fixed (#708)
1212

R/bag_mars.R

Lines changed: 7 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -65,36 +65,20 @@ update.bag_mars <-
6565
parameters = NULL,
6666
num_terms = NULL, prod_degree = NULL, prune_method = NULL,
6767
fresh = FALSE, ...) {
68-
update_dot_check(...)
6968

70-
if (!is.null(parameters)) {
71-
parameters <- check_final_param(parameters)
72-
}
7369
args <- list(
7470
num_terms = enquo(num_terms),
7571
prod_degree = enquo(prod_degree),
7672
prune_method = enquo(prune_method)
7773
)
7874

79-
args <- update_main_parameters(args, parameters)
80-
81-
if (fresh) {
82-
object$args <- args
83-
} else {
84-
null_args <- map_lgl(args, null_value)
85-
if (any(null_args))
86-
args <- args[!null_args]
87-
if (length(args) > 0)
88-
object$args[names(args)] <- args
89-
}
90-
91-
new_model_spec(
92-
"bag_mars",
93-
args = object$args,
94-
eng_args = object$eng_args,
95-
mode = object$mode,
96-
method = NULL,
97-
engine = object$engine
75+
update_spec(
76+
object = object,
77+
parameters = parameters,
78+
args_enquo_list = args,
79+
fresh = fresh,
80+
cls = "bag_mars",
81+
...
9882
)
9983
}
10084

R/bag_tree.R

Lines changed: 11 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -71,37 +71,21 @@ update.bag_tree <-
7171
cost_complexity = NULL, tree_depth = NULL, min_n = NULL,
7272
class_cost = NULL,
7373
fresh = FALSE, ...) {
74-
update_dot_check(...)
7574

76-
if (!is.null(parameters)) {
77-
parameters <- check_final_param(parameters)
78-
}
7975
args <- list(
80-
cost_complexity = enquo(cost_complexity),
81-
tree_depth = enquo(tree_depth),
82-
min_n = enquo(min_n),
83-
class_cost = enquo(class_cost)
76+
cost_complexity = enquo(cost_complexity),
77+
tree_depth = enquo(tree_depth),
78+
min_n = enquo(min_n),
79+
class_cost = enquo(class_cost)
8480
)
8581

86-
args <- update_main_parameters(args, parameters)
87-
88-
if (fresh) {
89-
object$args <- args
90-
} else {
91-
null_args <- map_lgl(args, null_value)
92-
if (any(null_args))
93-
args <- args[!null_args]
94-
if (length(args) > 0)
95-
object$args[names(args)] <- args
96-
}
97-
98-
new_model_spec(
99-
"bag_tree",
100-
args = object$args,
101-
eng_args = object$eng_args,
102-
mode = object$mode,
103-
method = NULL,
104-
engine = object$engine
82+
update_spec(
83+
object = object,
84+
parameters = parameters,
85+
args_enquo_list = args,
86+
fresh = fresh,
87+
cls = "bag_tree",
88+
...
10589
)
10690
}
10791

R/bart.R

Lines changed: 7 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -121,41 +121,20 @@ update.bart <-
121121
prior_outcome_range = NULL,
122122
fresh = FALSE, ...) {
123123

124-
eng_args <- update_engine_parameters(object$eng_args, ...)
125-
126-
if (!is.null(parameters)) {
127-
parameters <- check_final_param(parameters)
128-
}
129-
130124
args <- list(
131125
trees = enquo(trees),
132126
prior_terminal_node_coef = enquo(prior_terminal_node_coef),
133127
prior_terminal_node_expo = enquo(prior_terminal_node_expo),
134128
prior_outcome_range = enquo(prior_outcome_range)
135129
)
136130

137-
args <- update_main_parameters(args, parameters)
138-
139-
if (fresh) {
140-
object$args <- args
141-
object$eng_args <- eng_args
142-
} else {
143-
null_args <- map_lgl(args, null_value)
144-
if (any(null_args))
145-
args <- args[!null_args]
146-
if (length(args) > 0)
147-
object$args[names(args)] <- args
148-
if (length(eng_args) > 0)
149-
object$eng_args[names(eng_args)] <- eng_args
150-
}
151-
152-
new_model_spec(
153-
"bart",
154-
args = object$args,
155-
eng_args = object$eng_args,
156-
mode = object$mode,
157-
method = NULL,
158-
engine = object$engine
131+
update_spec(
132+
object = object,
133+
parameters = parameters,
134+
args_enquo_list = args,
135+
fresh = fresh,
136+
cls = "bart",
137+
...
159138
)
160139
}
161140

R/boost_tree.R

Lines changed: 7 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -105,12 +105,6 @@ update.boost_tree <-
105105
stop_iter = NULL,
106106
fresh = FALSE, ...) {
107107

108-
eng_args <- update_engine_parameters(object$eng_args, ...)
109-
110-
if (!is.null(parameters)) {
111-
parameters <- check_final_param(parameters)
112-
}
113-
114108
args <- list(
115109
mtry = enquo(mtry),
116110
trees = enquo(trees),
@@ -122,29 +116,13 @@ update.boost_tree <-
122116
stop_iter = enquo(stop_iter)
123117
)
124118

125-
args <- update_main_parameters(args, parameters)
126-
127-
# TODO make these blocks into a function and document well
128-
if (fresh) {
129-
object$args <- args
130-
object$eng_args <- eng_args
131-
} else {
132-
null_args <- map_lgl(args, null_value)
133-
if (any(null_args))
134-
args <- args[!null_args]
135-
if (length(args) > 0)
136-
object$args[names(args)] <- args
137-
if (length(eng_args) > 0)
138-
object$eng_args[names(eng_args)] <- eng_args
139-
}
140-
141-
new_model_spec(
142-
"boost_tree",
143-
args = object$args,
144-
eng_args = object$eng_args,
145-
mode = object$mode,
146-
method = NULL,
147-
engine = object$engine
119+
update_spec(
120+
object = object,
121+
parameters = parameters,
122+
args_enquo_list = args,
123+
fresh = fresh,
124+
cls = "boost_tree",
125+
...
148126
)
149127
}
150128

R/c5_rules.R

Lines changed: 7 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -100,35 +100,19 @@ update.C5_rules <-
100100
parameters = NULL,
101101
trees = NULL, min_n = NULL,
102102
fresh = FALSE, ...) {
103-
update_dot_check(...)
104103

105-
if (!is.null(parameters)) {
106-
parameters <- check_final_param(parameters)
107-
}
108104
args <- list(
109105
trees = enquo(trees),
110106
min_n = enquo(min_n)
111107
)
112108

113-
args <- update_main_parameters(args, parameters)
114-
115-
if (fresh) {
116-
object$args <- args
117-
} else {
118-
null_args <- map_lgl(args, null_value)
119-
if (any(null_args))
120-
args <- args[!null_args]
121-
if (length(args) > 0)
122-
object$args[names(args)] <- args
123-
}
124-
125-
new_model_spec(
126-
"C5_rules",
127-
args = object$args,
128-
eng_args = object$eng_args,
129-
mode = object$mode,
130-
method = NULL,
131-
engine = object$engine
109+
update_spec(
110+
object = object,
111+
parameters = parameters,
112+
args_enquo_list = args,
113+
fresh = fresh,
114+
cls = "C5_rules",
115+
...
132116
)
133117
}
134118

R/cubist_rules.R

Lines changed: 9 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -124,36 +124,20 @@ update.cubist_rules <-
124124
parameters = NULL,
125125
committees = NULL, neighbors = NULL, max_rules = NULL,
126126
fresh = FALSE, ...) {
127-
update_dot_check(...)
128127

129-
if (!is.null(parameters)) {
130-
parameters <- check_final_param(parameters)
131-
}
132128
args <- list(
133129
committees = enquo(committees),
134-
neighbors = enquo(neighbors),
135-
max_rules = enquo(max_rules)
130+
neighbors = enquo(neighbors),
131+
max_rules = enquo(max_rules)
136132
)
137133

138-
args <- update_main_parameters(args, parameters)
139-
140-
if (fresh) {
141-
object$args <- args
142-
} else {
143-
null_args <- map_lgl(args, null_value)
144-
if (any(null_args))
145-
args <- args[!null_args]
146-
if (length(args) > 0)
147-
object$args[names(args)] <- args
148-
}
149-
150-
new_model_spec(
151-
"cubist_rules",
152-
args = object$args,
153-
eng_args = object$eng_args,
154-
mode = object$mode,
155-
method = NULL,
156-
engine = object$engine
134+
update_spec(
135+
object = object,
136+
parameters = parameters,
137+
args_enquo_list = args,
138+
fresh = fresh,
139+
cls = "cubist_rules",
140+
...
157141
)
158142
}
159143

R/decision_tree.R

Lines changed: 7 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -74,39 +74,19 @@ update.decision_tree <-
7474
cost_complexity = NULL, tree_depth = NULL, min_n = NULL,
7575
fresh = FALSE, ...) {
7676

77-
eng_args <- update_engine_parameters(object$eng_args, ...)
78-
79-
if (!is.null(parameters)) {
80-
parameters <- check_final_param(parameters)
81-
}
8277
args <- list(
8378
cost_complexity = enquo(cost_complexity),
8479
tree_depth = enquo(tree_depth),
8580
min_n = enquo(min_n)
8681
)
8782

88-
args <- update_main_parameters(args, parameters)
89-
90-
if (fresh) {
91-
object$args <- args
92-
object$eng_args <- eng_args
93-
} else {
94-
null_args <- map_lgl(args, null_value)
95-
if (any(null_args))
96-
args <- args[!null_args]
97-
if (length(args) > 0)
98-
object$args[names(args)] <- args
99-
if (length(eng_args) > 0)
100-
object$eng_args[names(eng_args)] <- eng_args
101-
}
102-
103-
new_model_spec(
104-
"decision_tree",
105-
args = object$args,
106-
eng_args = object$eng_args,
107-
mode = object$mode,
108-
method = NULL,
109-
engine = object$engine
83+
update_spec(
84+
object = object,
85+
parameters = parameters,
86+
args_enquo_list = args,
87+
fresh = fresh,
88+
cls = "decision_tree",
89+
...
11090
)
11191
}
11292

R/discrim_flexible.R

Lines changed: 8 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -75,30 +75,20 @@ update.discrim_flexible <-
7575
prod_degree = NULL,
7676
prune_method = NULL,
7777
fresh = FALSE, ...) {
78-
update_dot_check(...)
78+
7979
args <- list(
8080
num_terms = enquo(num_terms),
8181
prod_degree = enquo(prod_degree),
8282
prune_method = enquo(prune_method)
8383
)
8484

85-
if (fresh) {
86-
object$args <- args
87-
} else {
88-
null_args <- map_lgl(args, null_value)
89-
if (any(null_args))
90-
args <- args[!null_args]
91-
if (length(args) > 0)
92-
object$args[names(args)] <- args
93-
}
94-
95-
new_model_spec(
96-
"discrim_flexible",
97-
args = object$args,
98-
eng_args = object$eng_args,
99-
mode = object$mode,
100-
method = NULL,
101-
engine = object$engine
85+
update_spec(
86+
object = object,
87+
parameters = NULL,
88+
args_enquo_list = args,
89+
fresh = fresh,
90+
cls = "discrim_flexible",
91+
...
10292
)
10393
}
10494

0 commit comments

Comments
 (0)