Skip to content

Commit c7e640a

Browse files
authored
Merge pull request #321 from tidymodels/engine-specific_defaults
Add defaults to engine specific params in model docs
2 parents 8fd1a87 + 73dbb73 commit c7e640a

29 files changed

+341
-125
lines changed

NAMESPACE

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,6 @@ export(boost_tree)
102102
export(check_empty_ellipse)
103103
export(check_final_param)
104104
export(control_parsnip)
105-
export(convert_args)
106105
export(convert_stan_interval)
107106
export(decision_tree)
108107
export(eval_args)

R/aaa.R

Lines changed: 0 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -30,33 +30,6 @@ convert_stan_interval <- function(x, level = 0.95, lower = TRUE) {
3030
res
3131
}
3232

33-
#' Make a table of arguments
34-
#' @param model_name A character string for the model
35-
#' @keywords internal
36-
#' @export
37-
convert_args <- function(model_name) {
38-
envir <- get_model_env()
39-
40-
args <-
41-
ls(envir) %>%
42-
tibble::tibble(name = .) %>%
43-
dplyr::filter(grepl("args", name)) %>%
44-
dplyr::mutate(model = sub("_args", "", name),
45-
args = purrr::map(name, ~envir[[.x]])) %>%
46-
tidyr::unnest(args) %>%
47-
dplyr::select(model:original)
48-
49-
convert_df <- args %>%
50-
dplyr::filter(grepl(model_name, model)) %>%
51-
dplyr::select(-model) %>%
52-
tidyr::pivot_wider(names_from = engine, values_from = original)
53-
54-
convert_df %>%
55-
knitr::kable(col.names = paste0("**", colnames(convert_df), "**"))
56-
57-
}
58-
59-
6033
# ------------------------------------------------------------------------------
6134
# nocov
6235

R/boost_tree_data.R

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -338,8 +338,8 @@ set_model_arg(
338338
set_model_arg(
339339
model = "boost_tree",
340340
eng = "spark",
341-
parsnip = "min_info_gain",
342-
original = "loss_reduction",
341+
parsnip = "loss_reduction",
342+
original = "min_info_gain",
343343
func = list(pkg = "dials", fun = "loss_reduction"),
344344
has_submodel = FALSE
345345
)

man/boost_tree.Rd

Lines changed: 14 additions & 9 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/convert_args.Rd

Lines changed: 0 additions & 15 deletions
This file was deleted.

man/decision_tree.Rd

Lines changed: 7 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/linear_reg.Rd

Lines changed: 5 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/logistic_reg.Rd

Lines changed: 5 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/mars.Rd

Lines changed: 5 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/mlp.Rd

Lines changed: 10 additions & 8 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/multinom_reg.Rd

Lines changed: 5 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/nearest_neighbor.Rd

Lines changed: 5 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/rand_forest.Rd

Lines changed: 15 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/rmd/boost-tree.Rmd

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
# Engine Details
22

3+
```{r, child = "setup.Rmd", include = FALSE}
4+
```
5+
36
Engines may have pre-set default arguments when executing the model fit call. For this type of model, the template of the fit calls are below:
47

58
## xgboost
@@ -50,9 +53,33 @@ boost_tree() %>%
5053

5154
## Parameter translations
5255

53-
The standardized parameter names in parsnip can be mapped to their original names in each engine that has main parameters:
56+
The standardized parameter names in parsnip can be mapped to their original names in each engine that has main parameters. Each engine typically has a different default value (shown in parentheses) for each parameter.
5457

5558
```{r echo = FALSE, results = "asis"}
56-
parsnip::convert_args("boost_tree")
59+
get_defaults_boost_tree <- function() {
60+
tibble::tribble(
61+
~model, ~engine, ~parsnip, ~original, ~default,
62+
"boost_tree", "xgboost", "tree_depth", "max_depth", get_arg("parsnip", "xgb_train", "max_depth"),
63+
"boost_tree", "xgboost", "trees", "nrounds", get_arg("parsnip", "xgb_train", "nrounds"),
64+
"boost_tree", "xgboost", "learn_rate", "eta", get_arg("parsnip", "xgb_train", "eta"),
65+
"boost_tree", "xgboost", "mtry", "colsample_bytree", get_arg("parsnip", "xgb_train", "colsample_bytree"),
66+
"boost_tree", "xgboost", "min_n", "min_child_weight", get_arg("parsnip", "xgb_train", "min_child_weight"),
67+
"boost_tree", "xgboost", "loss_reduction", "gamma", get_arg("parsnip", "xgb_train", "gamma"),
68+
"boost_tree", "xgboost", "sample_size", "subsample", get_arg("parsnip", "xgb_train", "subsample"),
69+
"boost_tree", "C5.0", "trees", "trials", get_arg("parsnip", "C5.0_train", "trials"),
70+
"boost_tree", "C5.0", "min_n", "minCases", get_arg("C50", "C5.0Control", "minCases"),
71+
"boost_tree", "C5.0", "sample_size", "sample", get_arg("C50", "C5.0Control", "sample"),
72+
"boost_tree", "spark", "tree_depth", "max_depth", get_arg("sparklyr", "ml_gradient_boosted_trees", "max_depth"),
73+
"boost_tree", "spark", "trees", "max_iter", get_arg("sparklyr", "ml_gradient_boosted_trees", "max_iter"),
74+
"boost_tree", "spark", "learn_rate", "step_size", get_arg("sparklyr", "ml_gradient_boosted_trees", "step_size"),
75+
"boost_tree", "spark", "mtry", "feature_subset_strategy", "see below",
76+
"boost_tree", "spark", "min_n", "min_instances_per_node", get_arg("sparklyr", "ml_gradient_boosted_trees", "min_instances_per_node"),
77+
"boost_tree", "spark", "loss_reduction", "min_info_gain", get_arg("sparklyr", "ml_gradient_boosted_trees", "min_info_gain"),
78+
"boost_tree", "spark", "sample_size", "subsampling_rate", get_arg("sparklyr", "ml_gradient_boosted_trees", "subsampling_rate"),
79+
80+
)
81+
}
82+
convert_args("boost_tree")
5783
```
5884

85+
For spark, the default `mtry` is the square root of the number of predictors for classification, and one-third of the predictors for regression.

man/rmd/decision-tree.Rmd

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
# Engine Details
22

3+
```{r, child = "setup.Rmd", include = FALSE}
4+
```
5+
36
Engines may have pre-set default arguments when executing the model fit call. For this type of model, the template of the fit calls are below:
47

58
## rpart
@@ -52,9 +55,20 @@ decision_tree() %>%
5255

5356
## Parameter translations
5457

55-
The standardized parameter names in parsnip can be mapped to their original names in each engine that has main parameters:
58+
The standardized parameter names in parsnip can be mapped to their original names in each engine that has main parameters. Each engine typically has a different default value (shown in parentheses) for each parameter.
5659

5760
```{r echo = FALSE, results = "asis"}
58-
parsnip::convert_args("decision_tree")
61+
get_defaults_decision_tree <- function() {
62+
tibble::tribble(
63+
~model, ~engine, ~parsnip, ~original, ~default,
64+
"decision_tree", "rpart", "tree_depth", "maxdepth", get_arg("rpart", "rpart.control", "maxdepth"),
65+
"decision_tree", "rpart", "min_n", "minsplit", get_arg("rpart", "rpart.control", "minsplit"),
66+
"decision_tree", "rpart", "cost_complexity", "cp", get_arg("rpart", "rpart.control", "cp"),
67+
"decision_tree", "C5.0", "min_n", "minCases", get_arg("C50", "C5.0Control", "minCases"),
68+
"decision_tree", "spark", "tree_depth", "max_depth", get_arg("sparklyr", "ml_decision_tree", "max_depth"),
69+
"decision_tree", "spark", "min_n", "min_instances_per_node", get_arg("sparklyr", "ml_decision_tree", "min_instances_per_node"),
70+
)
71+
}
72+
convert_args("decision_tree")
5973
```
6074

man/rmd/linear-reg.Rmd

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
# Engine Details
22

3+
```{r, child = "setup.Rmd", include = FALSE}
4+
```
5+
36
Engines may have pre-set default arguments when executing the model fit call. For this type of model, the template of the fit calls are below.
47

58
## lm
@@ -68,10 +71,20 @@ linear_reg() %>%
6871

6972
## Parameter translations
7073

71-
The standardized parameter names in parsnip can be mapped to their original names
72-
in each engine that has main parameters:
74+
The standardized parameter names in parsnip can be mapped to their original
75+
names in each engine that has main parameters. Each engine typically has a
76+
different default value (shown in parentheses) for each parameter.
7377

7478
```{r echo = FALSE, results = "asis"}
75-
parsnip::convert_args("linear_reg")
79+
get_defaults_linear_reg <- function() {
80+
tibble::tribble(
81+
~model, ~engine, ~parsnip, ~original, ~default,
82+
"linear_reg", "glmnet", "mixture", "alpha", get_arg("glmnet", "glmnet", "alpha"),
83+
"linear_reg", "spark", "penalty", "reg_param", get_arg("sparklyr", "ml_linear_regression", "reg_param"),
84+
"linear_reg", "spark", "mixture", "elastic_net_param", get_arg("sparklyr", "ml_linear_regression", "elastic_net_param"),
85+
"linear_reg", "keras", "penalty", "penalty", get_arg("parsnip", "keras_mlp", "penalty"),
86+
)
87+
}
88+
convert_args("linear_reg")
7689
```
7790

0 commit comments

Comments
 (0)