Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions .github/workflows/R-CMD-check.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
on:
push:
branches:
- master
pull_request:
types: [opened, synchronize, reopened]
branches:
- master

name: R-CMD-check

Expand All @@ -18,7 +21,7 @@ jobs:
- {os: macOS-latest, r: 'release'}
- {os: windows-latest, r: 'release'}
- {os: windows-latest, r: '3.6'}
- {os: ubuntu-16.04, r: 'devel', rspm: "https://packagemanager.rstudio.com/cran/__linux__/xenial/latest"}
- {os: ubuntu-16.04, r: 'devel', rspm: "https://packagemanager.rstudio.com/cran/__linux__/xenial/latest", http-user-agent: "R/4.0.0 (ubuntu-16.04) R (4.0.0 x86_64-pc-linux-gnu x86_64 linux-gnu) on GitHub Actions" }
- {os: ubuntu-16.04, r: 'release', rspm: "https://packagemanager.rstudio.com/cran/__linux__/xenial/latest"}
- {os: ubuntu-16.04, r: 'oldrel', rspm: "https://packagemanager.rstudio.com/cran/__linux__/xenial/latest"}
- {os: ubuntu-16.04, r: '3.5', rspm: "https://packagemanager.rstudio.com/cran/__linux__/xenial/latest"}
Expand All @@ -34,6 +37,7 @@ jobs:
- uses: r-lib/actions/setup-r@master
with:
r-version: ${{ matrix.config.r }}
http-user-agent: ${{ matrix.config.http-user-agent }}

- uses: r-lib/actions/setup-pandoc@master

Expand Down Expand Up @@ -79,7 +83,7 @@ jobs:
run: |
reticulate::conda_create('r-reticulate', packages = c('python==3.6.9'))
tensorflow::install_tensorflow(version='1.14.0')
shell: Rscript {0}
shell: Rscript {0}

- name: Session info
run: |
Expand Down
1 change: 1 addition & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,7 @@ export(set_model_mode)
export(set_new_model)
export(set_pred)
export(show_call)
export(show_engines)
export(show_fit)
export(show_model_info)
export(surv_reg)
Expand Down
2 changes: 2 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# parsnip (development version)

* `show_engines()` will provide information on the current set for a model.

# parsnip 0.1.3

* A `glance()` method for `model_fit` objects was added (#325)
Expand Down
4 changes: 4 additions & 0 deletions R/boost_tree.R
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@
#' \item \pkg{Spark}: `"spark"`
#' }
#'
#' For this model, other packages may add additional engines. Use
#' [show_engines()] to see the current set of engines.
#'
#' @includeRmd man/rmd/boost-tree.Rmd details
#'
Expand All @@ -81,6 +83,8 @@
#' @importFrom purrr map_lgl
#' @seealso [fit()], [set_engine()]
#' @examples
#' show_engines("boost_tree")
#'
#' boost_tree(mode = "classification", trees = 20)
#' # Parameters can be represented by a placeholder:
#' boost_tree(mode = "regression", mtry = varying())
Expand Down
2 changes: 2 additions & 0 deletions R/decision_tree.R
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@
#' @importFrom purrr map_lgl
#' @seealso [fit()]
#' @examples
#' show_engines("decision_tree")
#'
#' decision_tree(mode = "classification", tree_depth = 5)
#' # Parameters can be represented by a placeholder:
#' decision_tree(mode = "regression", cost_complexity = varying())
Expand Down
21 changes: 21 additions & 0 deletions R/engines.R
Original file line number Diff line number Diff line change
Expand Up @@ -106,3 +106,24 @@ set_engine <- function(object, engine, ...) {
engine = object$engine
)
}

#' Display available engines for a model
#'
#' The possible engines for a model may depend on what packages are loaded. There
#' are some `parsnip`-adjacent packages that only add engines to existing models.
#' @param x The name of a `parsnip` model (e.g., "linear_reg", "mars", etc.)
#' @return A tibble.
#' show_engines("linear_reg")
#' @export
show_engines <- function(x) {
if (!is.character(x) || length(x) > 1) {
rlang::abort("`show_engines()` takes a single character string as input.")
}
res <- try(get_from_env(x), silent = TRUE)
if (inherits(res, "try-error")) {
rlang::abort(
paste0("No results found for model function '", x, "'.")
)
}
res
}
5 changes: 5 additions & 0 deletions R/linear_reg.R
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,9 @@
#' \item \pkg{keras}: `"keras"`
#' }
#'
#' For this model, other packages may add additional engines. Use
#' [show_engines()] to see the current set of engines.
#'
#' @includeRmd man/rmd/linear-reg.Rmd details
#'
#' @note For models created using the spark engine, there are
Expand All @@ -59,6 +62,8 @@
#'
#' @seealso [fit()], [set_engine()]
#' @examples
#' show_engines("linear_reg")
#'
#' linear_reg()
#' # Parameters can be represented by a placeholder:
#' linear_reg(penalty = varying())
Expand Down
5 changes: 5 additions & 0 deletions R/logistic_reg.R
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@
#' \item \pkg{keras}: `"keras"`
#' }
#'
#' For this model, other packages may add additional engines. Use
#' [show_engines()] to see the current set of engines.
#'
#' @includeRmd man/rmd/logistic-reg.Rmd details
#'
#' @note For models created using the spark engine, there are
Expand All @@ -57,6 +60,8 @@
#'
#' @seealso [fit()]
#' @examples
#' show_engines("logistic_reg")
#'
#' logistic_reg()
#' # Parameters can be represented by a placeholder:
#' logistic_reg(penalty = varying())
Expand Down
2 changes: 2 additions & 0 deletions R/mars.R
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@
#' @importFrom purrr map_lgl
#' @seealso [fit()]
#' @examples
#' show_engines("mars")
#'
#' mars(mode = "regression", num_terms = 5)
#' @export
mars <-
Expand Down
2 changes: 2 additions & 0 deletions R/mlp.R
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@
#' @importFrom purrr map_lgl
#' @seealso [fit()]
#' @examples
#' show_engines("mlp")
#'
#' mlp(mode = "classification", penalty = 0.01)
#' # Parameters can be represented by a placeholder:
#' mlp(mode = "regression", hidden_units = varying())
Expand Down
2 changes: 2 additions & 0 deletions R/multinom_reg.R
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@
#'
#' @seealso [fit()]
#' @examples
#' show_engines("multinom_reg")
#'
#' multinom_reg()
#' # Parameters can be represented by a placeholder:
#' multinom_reg(penalty = varying())
Expand Down
2 changes: 2 additions & 0 deletions R/nearest_neighbor.R
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@
#' @seealso [fit()]
#'
#' @examples
#' show_engines("nearest_neighbor")
#'
#' nearest_neighbor(neighbors = 11)
#'
#' @export
Expand Down
2 changes: 2 additions & 0 deletions R/rand_forest.R
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@
#' @importFrom purrr map_lgl
#' @seealso [fit()]
#' @examples
#' show_engines("rand_forest")
#'
#' rand_forest(mode = "classification", trees = 2000)
#' # Parameters can be represented by a placeholder:
#' rand_forest(mode = "regression", mtry = varying())
Expand Down
2 changes: 2 additions & 0 deletions R/surv_reg.R
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@
#' @references Jackson, C. (2016). `flexsurv`: A Platform for Parametric Survival
#' Modeling in R. _Journal of Statistical Software_, 70(8), 1 - 33.
#' @examples
#' show_engines("surv_reg")
#'
#' surv_reg()
#' # Parameters can be represented by a placeholder:
#' surv_reg(dist = varying())
Expand Down
2 changes: 2 additions & 0 deletions R/svm_poly.R
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@
#' @importFrom purrr map_lgl
#' @seealso [fit()]
#' @examples
#' show_engines("svm_poly")
#'
#' svm_poly(mode = "classification", degree = 1.2)
#' # Parameters can be represented by a placeholder:
#' svm_poly(mode = "regression", cost = varying())
Expand Down
2 changes: 2 additions & 0 deletions R/svm_rbf.R
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@
#' @importFrom purrr map_lgl
#' @seealso [fit()]
#' @examples
#' show_engines("svm_rbf")
#'
#' svm_rbf(mode = "classification", rbf_sigma = 0.2)
#' # Parameters can be represented by a placeholder:
#' svm_rbf(mode = "regression", cost = varying())
Expand Down
13 changes: 13 additions & 0 deletions man/boost_tree.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions man/decision_tree.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions man/linear_reg.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions man/logistic_reg.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions man/mars.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions man/mlp.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions man/multinom_reg.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions man/nearest_neighbor.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions man/rand_forest.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions man/rmd/boost-tree.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@ mod_param <-
update(sample_size = sample_prop(c(0.4, 0.9)))
```

For this engine, tuning over `trees` is very efficient since the same model
object can be used to make predictions over multiple values of `trees`.

Finally, note that `xgboost` models require that non-numeric predictors (e.g., factors) must be converted to dummy variables or some other numeric representation. By default, when using `fit()` with `xgboost`, a one-hot encoding is used to convert factor predictors to indicator variables.


Expand All @@ -52,6 +55,9 @@ boost_tree() %>%

Note that [C50::C5.0()] does not require factor predictors to be converted to indicator variables. `fit()` does not affect the encoding of the predictor values (i.e. factors stay factors) for this model.

For this engine, tuning over `trees` is very efficient since the same model
object can be used to make predictions over multiple values of `trees`.

## spark

```{r spark-reg}
Expand Down
2 changes: 2 additions & 0 deletions man/rmd/mars.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ Note that, when the model is fit, the `earth` package only has its namespace lo

Also, `fit()` passes the data directly to `earth::earth()` so that its formula method can create dummy variables as-needed.

For this engine, tuning over `num_terms` is very efficient since the same model
object can be used to make predictions over multiple values of `num_terms`.

## Parameter translations

Expand Down
Loading