Skip to content

Commit 82ae63b

Browse files
committed
updated parameter ranges and loosened constraints on dials specification
1 parent d222525 commit 82ae63b

File tree

7 files changed

+24
-17
lines changed

7 files changed

+24
-17
lines changed

NEWS.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# parsnip 0.0.3.9000
22

3-
3+
* Some default parameter ranges were updated for SVM, KNN, and MARS models.
44

55
# parsnip 0.0.3.1
66

R/aaa_models.R

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -160,10 +160,11 @@ check_func_val <- function(func) {
160160
msg <-
161161
paste(
162162
"`func` should be a named vector with element 'fun' and the optional ",
163-
"element 'pkg'. These should both be single character strings."
163+
"elements 'pkg', 'range', 'trans', and 'values'.",
164+
"`func` and 'pkg' should both be single character strings."
164165
)
165166

166-
if (rlang::is_missing(func) || !is.vector(func) || length(func) > 2)
167+
if (rlang::is_missing(func) || !is.vector(func))
167168
stop(msg, call. = FALSE)
168169

169170
nms <- sort(names(func))
@@ -177,13 +178,19 @@ check_func_val <- function(func) {
177178
stop(msg, call. = FALSE)
178179
}
179180
} else {
180-
if (!isTRUE(all.equal(nms, c("fun", "pkg")))) {
181+
# check for extra names:
182+
allow_nms <- c("fun", "pkg", "range", "trans", "values")
183+
nm_check <- nms %in% c("fun", "pkg", "range", "trans", "values")
184+
not_allowed <- nms[!(nms %in% allow_nms)]
185+
if (length(not_allowed) > 0) {
181186
stop(msg, call. = FALSE)
182187
}
183188
}
184189

185-
186-
if (!all(purrr::map_lgl(func, is.character))) {
190+
if (!is.character(func[["fun"]])) {
191+
stop(msg, call. = FALSE)
192+
}
193+
if (any(nms == "pkg") && !is.character(func[["pkg"]])) {
187194
stop(msg, call. = FALSE)
188195
}
189196

R/mars_data.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ set_model_arg(
1515
eng = "earth",
1616
parsnip = "num_terms",
1717
original = "nprune",
18-
func = list(pkg = "dials", fun = "num_terms"),
18+
func = list(pkg = "dials", fun = "num_terms", range = c(2:5)),
1919
has_submodel = TRUE
2020
)
2121
set_model_arg(

R/nearest_neighbor_data.R

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ set_model_arg(
1515
eng = "kknn",
1616
parsnip = "neighbors",
1717
original = "ks",
18-
func = list(pkg = "dials", fun = "neighbors"),
18+
func = list(pkg = "dials", fun = "neighbors", range = c(1, 15)),
1919
has_submodel = TRUE
2020
)
2121
set_model_arg(
@@ -31,7 +31,7 @@ set_model_arg(
3131
eng = "kknn",
3232
parsnip = "dist_power",
3333
original = "distance",
34-
func = list(pkg = "dials", fun = "distance"),
34+
func = list(pkg = "dials", fun = "dist_power", range = c(1/10, 2)),
3535
has_submodel = FALSE
3636
)
3737

R/svm_poly_data.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ set_model_arg(
1414
eng = "kernlab",
1515
parsnip = "cost",
1616
original = "C",
17-
func = list(pkg = "dials", fun = "cost"),
17+
func = list(pkg = "dials", fun = "cost", range = c(-10, 5)),
1818
has_submodel = FALSE
1919
)
2020

R/svm_rbf_data.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ set_model_arg(
1414
eng = "kernlab",
1515
parsnip = "cost",
1616
original = "C",
17-
func = list(pkg = "dials", fun = "cost"),
17+
func = list(pkg = "dials", fun = "cost", range = c(-10, 5)),
1818
has_submodel = FALSE
1919
)
2020

vignettes/articles/Scratch.Rmd

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -79,15 +79,15 @@ These functions should silently finish. There is also a function that can be use
7979
show_model_info("mixture_da")
8080
```
8181

82-
The next step would be the declare the main arguments to the model. These are declared indpendnent of the mode. To specifiy the argument, there are a few slots to fill in:
82+
The next step would be the declare the main arguments to the model. These are declared independent of the mode. To specify the argument, there are a few slots to fill in:
8383

84-
* The name that `parsnip` uses for the argument. In general, we try to use non-jargony names for arguments (e.g. "penalty" instead of "lambda" for regularised regression). We recommend consulting [this page]() to see if an existing argument name can be used before creating a new one.
84+
* The name that `parsnip` uses for the argument. In general, we try to use non-jargony names for arguments (e.g. "penalty" instead of "lambda" for regularized regression). We recommend consulting [this page]() to see if an existing argument name can be used before creating a new one.
8585

8686
* The argument name that is used by the underlying modeling function.
8787

88-
* A function reference for a _contructor_ that will be used to generate tuning parameter values. This should be a character vector that has a named element called `fun` that is the contructor function. There is an optional element `pkg` that can be used to call the function using its namespace.
88+
* A function reference for a _constructor_ that will be used to generate tuning parameter values. This should be a character vector that has a named element called `fun` that is the constructor function. There is an optional element `pkg` that can be used to call the function using its namespace. If referencing functions from the `dials` package, quantitative parameters can have additional arguments in the list for `trans` and `range` while qualitative parameters can pass `values` via this list.
8989

90-
* A logical value for wether the argument can be used to generate mutiple predictions for a single R object. For example, for boosted trees, if a model is fit with 10 boosting iterations, many modeling packages allow the model object to make predictions for any iterations less than the one used to fit the model. In general this is not the case so one would use `has_submodels = FALSE`.
90+
* A logical value for wether the argument can be used to generate multiple predictions for a single R object. For example, for boosted trees, if a model is fit with 10 boosting iterations, many modeling packages allow the model object to make predictions for any iterations less than the one used to fit the model. In general this is not the case so one would use `has_submodels = FALSE`.
9191

9292
For `mda::mda()`, the main tuning parameter is `subclasses` which we will rewrite as `sub_classes`.
9393

@@ -138,8 +138,7 @@ This is pretty simple since the data are not exposed to this function.
138138

139139
## Step 3. Add a Fit Module
140140

141-
Now that `parsnip` knows about the model, mode, and engine, we can give it the infomration on fitting the model for our engine.
142-
In infomration needed to fit the model is contained in another list. The elements are:
141+
Now that `parsnip` knows about the model, mode, and engine, we can give it the information on fitting the model for our engine. The information needed to fit the model is contained in another list. The elements are:
143142

144143
* `interface` a single character value that could be "formula", "data.frame", or "matrix". This defines the type of interface used by the underlying fit function (`mda::mda`, in this case). This helps the translation of the data to be in an appropriate format for the that function.
145144

@@ -426,3 +425,4 @@ Not yet but there will be. For example, it might make sense to have a different
426425

427426
If you have a suggestion, please ad a GitHub issue to discuss it.
428427

428+

0 commit comments

Comments
 (0)