Skip to content

Add a model for bagged neural networks #815

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 8 commits into from
Sep 26, 2022
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
2 changes: 2 additions & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ S3method(type_sum,model_fit)
S3method(type_sum,model_spec)
S3method(update,C5_rules)
S3method(update,bag_mars)
S3method(update,bag_mlp)
S3method(update,bag_tree)
S3method(update,bart)
S3method(update,boost_tree)
Expand Down Expand Up @@ -146,6 +147,7 @@ export(augment)
export(auto_ml)
export(autoplot)
export(bag_mars)
export(bag_mlp)
export(bag_tree)
export(bart)
export(bartMachine_interval_calc)
Expand Down
77 changes: 77 additions & 0 deletions R/bag_mlp.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
#' Ensembles of neural networks
#'
#' @description
#'
#' `bag_mlp()` defines an ensemble of single layer, feed-forward neural networks.
#' This function can fit classification and regression models.
#'
#' \Sexpr[stage=render,results=rd]{parsnip:::make_engine_list("bag_mlp")}
#'
#' More information on how \pkg{parsnip} is used for modeling is at
#' \url{https://www.tidymodels.org/}.
#'
#' @inheritParams mlp
#'
#' @template spec-details
#'
#' @template spec-references
#'
#' @seealso \Sexpr[stage=render,results=rd]{parsnip:::make_seealso_list("bag_mlp")}
#' @export
bag_mlp <-
function(mode = "unknown",
hidden_units = NULL,
penalty = NULL,
epochs = NULL,
engine = "nnet") {
args <- list(
hidden_units = enquo(hidden_units),
penalty = enquo(penalty),
epochs = enquo(epochs)
)

new_model_spec(
"bag_mlp",
args = args,
eng_args = NULL,
mode = mode,
user_specified_mode = !missing(mode),
method = NULL,
engine = engine,
user_specified_engine = !missing(engine)
)
}

# ------------------------------------------------------------------------------

#' @method update bag_mlp
#' @rdname parsnip_update
#' @inheritParams mars
#' @export
update.bag_mlp <-
function(object,
parameters = NULL,
hidden_units = NULL, penalty = NULL, epochs = NULL,
fresh = FALSE, ...) {

args <- list(
hidden_units = enquo(hidden_units),
penalty = enquo(penalty),
epochs = enquo(epochs)
)

update_spec(
object = object,
parameters = parameters,
args_enquo_list = args,
fresh = fresh,
cls = "bag_mlp",
...
)
}

# ------------------------------------------------------------------------------

set_new_model("bag_mlp")
set_model_mode("bag_mlp", "classification")
set_model_mode("bag_mlp", "regression")
12 changes: 12 additions & 0 deletions R/bag_mlp_nnet.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#' Bagged neural networks via nnet
#'
#' [baguette::bagger()] creates a collection of neural networks forming an
#' ensemble. All trees in the ensemble are combined to produce a final prediction.
#'
#' @includeRmd man/rmd/bag_mlp_nnet.md details
#'
#' @name details_bag_mlp_nnet
#' @keywords internal
NULL

# See inst/README-DOCS.md for a description of how these files are processed
1 change: 1 addition & 0 deletions R/print.R
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ model_descs <- tibble::tribble(
~cls, ~desc,
"auto_ml", "Automatic Machine Learning",
"bag_mars", "Bagged MARS",
"bag_mlp", "Bagged Neural Network",
"bag_tree", "Bagged Decision Tree",
"bart", "BART",
"boost_tree", "Boosted Tree",
Expand Down
1 change: 1 addition & 0 deletions _pkgdown.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ reference:
contents:
- auto_ml
- bag_mars
- bag_mlp
- bag_tree
- bart
- boost_tree
Expand Down
5 changes: 5 additions & 0 deletions inst/models.tsv
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
"auto_ml" "regression" "h2o" "agua"
"bag_mars" "classification" "earth" "baguette"
"bag_mars" "regression" "earth" "baguette"
"bag_mlp" "classification" "nnet" "baguette"
"bag_mlp" "regression" "nnet" "baguette"
"bag_tree" "censored regression" "rpart" "censored"
"bag_tree" "classification" "C5.0" "baguette"
"bag_tree" "classification" "rpart" "baguette"
Expand All @@ -12,10 +14,12 @@
"boost_tree" "censored regression" "mboost" "censored"
"boost_tree" "classification" "C5.0" NA
"boost_tree" "classification" "h2o" "agua"
"boost_tree" "classification" "h2o_gbm" "agua"
"boost_tree" "classification" "lightgbm" "bonsai"
"boost_tree" "classification" "spark" NA
"boost_tree" "classification" "xgboost" NA
"boost_tree" "regression" "h2o" "agua"
"boost_tree" "regression" "h2o_gbm" "agua"
"boost_tree" "regression" "lightgbm" "bonsai"
"boost_tree" "regression" "spark" NA
"boost_tree" "regression" "xgboost" NA
Expand Down Expand Up @@ -43,6 +47,7 @@
"linear_reg" "regression" "brulee" NA
"linear_reg" "regression" "gee" "multilevelmod"
"linear_reg" "regression" "glm" NA
"linear_reg" "regression" "glmer" "multilevelmod"
"linear_reg" "regression" "glmnet" NA
"linear_reg" "regression" "gls" "multilevelmod"
"linear_reg" "regression" "h2o" "agua"
Expand Down
53 changes: 53 additions & 0 deletions man/bag_mlp.Rd

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

9 changes: 4 additions & 5 deletions man/details_C5_rules_C5.0.Rd

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

10 changes: 5 additions & 5 deletions man/details_auto_ml_h2o.Rd

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

6 changes: 2 additions & 4 deletions man/details_bag_mars_earth.Rd

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

104 changes: 104 additions & 0 deletions man/details_bag_mlp_nnet.Rd

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

3 changes: 1 addition & 2 deletions man/details_bag_tree_C5.0.Rd

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

3 changes: 1 addition & 2 deletions man/details_bag_tree_rpart.Rd

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

Loading