diff --git a/NEWS.md b/NEWS.md index 5df18b57..342a46dd 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,4 +1,8 @@ -# mlr3learners 0.5.5 +# mlr3learners 0.5.6-9000 + +* Added formula argument to `nnet` learner and support feature type `"integer"` + +# mlr3learners 0.5.6 - Enable new early stopping mechanism for xgboost. - Improved documentation. diff --git a/R/LearnerClassifNnet.R b/R/LearnerClassifNnet.R index 615b69cf..a9d34720 100644 --- a/R/LearnerClassifNnet.R +++ b/R/LearnerClassifNnet.R @@ -17,6 +17,9 @@ #' - Adjusted default: 3L. #' - Reason for change: no default in `nnet()`. #' +#' @section Custom mlr3 parameters: +#' - `formula`: if not provided, the formula is set to `task$formula()`. +#' #' @references #' `r format_bib("ripley_1996")` #' @@ -46,14 +49,15 @@ LearnerClassifNnet = R6Class("LearnerClassifNnet", size = p_int(0L, default = 3L, tags = "train"), skip = p_lgl(default = FALSE, tags = "train"), subset = p_uty(tags = "train"), - trace = p_lgl(default = TRUE, tags = "train") + trace = p_lgl(default = TRUE, tags = "train"), + formula = p_uty(tags = "train") ) ps$values = list(size = 3L) super$initialize( id = "classif.nnet", packages = c("mlr3learners", "nnet"), - feature_types = c("numeric", "factor", "ordered"), + feature_types = c("numeric", "factor", "ordered", "integer"), predict_types = c("prob", "response"), param_set = ps, properties = c("twoclass", "multiclass", "weights"), @@ -68,9 +72,11 @@ LearnerClassifNnet = R6Class("LearnerClassifNnet", if ("weights" %in% task$properties) { pv = insert_named(pv, list(weights = task$weights$weight)) } - f = task$formula() + if (is.null(pv$formula)) { + pv$formula = task$formula() + } data = task$data() - invoke(nnet::nnet.formula, formula = f, data = data, .args = pv) + invoke(nnet::nnet.formula, data = data, .args = pv) }, .predict = function(task) { diff --git a/R/LearnerRegrNnet.R b/R/LearnerRegrNnet.R index 68c579ed..63c32baa 100644 --- a/R/LearnerRegrNnet.R +++ b/R/LearnerRegrNnet.R @@ -17,6 +17,9 @@ #' - Adjusted default: 3L. #' - Reason for change: no default in `nnet()`. #' +#' @section Custom mlr3 parameters: +#' - `formula`: if not provided, the formula is set to `task$formula()`. +#' #' @references #' `r format_bib("ripley_1996")` #' @@ -46,14 +49,15 @@ LearnerRegrNnet = R6Class("LearnerRegrNnet", size = p_int(0L, default = 3L, tags = "train"), skip = p_lgl(default = FALSE, tags = "train"), subset = p_uty(tags = "train"), - trace = p_lgl(default = TRUE, tags = "train") + trace = p_lgl(default = TRUE, tags = "train"), + formula = p_uty(tags = "train") ) ps$values = list(size = 3L) super$initialize( id = "regr.nnet", packages = c("mlr3learners", "nnet"), - feature_types = c("numeric", "factor", "ordered"), + feature_types = c("numeric", "factor", "ordered", "integer"), predict_types = c("response"), param_set = ps, properties = c("weights"), @@ -68,10 +72,12 @@ LearnerRegrNnet = R6Class("LearnerRegrNnet", if ("weights" %in% task$properties) { pv = insert_named(pv, list(weights = task$weights$weight)) } - f = task$formula() + if (is.null(pv$formula)) { + pv$formula = task$formula() + } data = task$data() # force linout = TRUE for regression - invoke(nnet::nnet.formula, formula = f, data = data, linout = TRUE, .args = pv) + invoke(nnet::nnet.formula, data = data, linout = TRUE, .args = pv) }, .predict = function(task) { diff --git a/inst/paramtest/test_paramtest_classif.nnet.R b/inst/paramtest/test_paramtest_classif.nnet.R index d7ed0351..7fb163ce 100644 --- a/inst/paramtest/test_paramtest_classif.nnet.R +++ b/inst/paramtest/test_paramtest_classif.nnet.R @@ -7,7 +7,6 @@ test_that("classif.nnet", { "x", # handled via mlr3 "y", # handled via mlr3 "weights", # handled via mlr3 - "formula", # handled via mlr3 "data", # handled via mlr3 "entropy", # automatically set to TRUE if two-class task "softmax", # automatically set to TRUE if multi-class task diff --git a/inst/paramtest/test_paramtest_regr.nnet.R b/inst/paramtest/test_paramtest_regr.nnet.R index d145c587..6cdfa2b8 100644 --- a/inst/paramtest/test_paramtest_regr.nnet.R +++ b/inst/paramtest/test_paramtest_regr.nnet.R @@ -7,7 +7,6 @@ test_that("regr.nnet", { "x", # handled via mlr3 "y", # handled via mlr3 "weights", # handled via mlr3 - "formula", # handled via mlr3 "data", # handled via mlr3 "linout", # automatically set to TRUE, since it's the regression learner "entropy", # mutually exclusive with linout diff --git a/man/mlr_learners_classif.nnet.Rd b/man/mlr_learners_classif.nnet.Rd index a7e0b028..85f8e694 100644 --- a/man/mlr_learners_classif.nnet.Rd +++ b/man/mlr_learners_classif.nnet.Rd @@ -25,7 +25,7 @@ lrn("classif.nnet") \itemize{ \item Task type: \dQuote{classif} \item Predict Types: \dQuote{response}, \dQuote{prob} -\item Feature Types: \dQuote{numeric}, \dQuote{factor}, \dQuote{ordered} +\item Feature Types: \dQuote{integer}, \dQuote{numeric}, \dQuote{factor}, \dQuote{ordered} \item Required Packages: \CRANpkg{mlr3}, \CRANpkg{mlr3learners}, \CRANpkg{nnet} } } @@ -49,6 +49,7 @@ lrn("classif.nnet") skip \tab logical \tab FALSE \tab TRUE, FALSE \tab - \cr subset \tab untyped \tab - \tab \tab - \cr trace \tab logical \tab TRUE \tab TRUE, FALSE \tab - \cr + formula \tab untyped \tab - \tab \tab - \cr } } @@ -63,6 +64,13 @@ lrn("classif.nnet") } } +\section{Custom mlr3 parameters}{ + +\itemize{ +\item \code{formula}: if not provided, the formula is set to \code{task$formula()}. +} +} + \examples{ if (requireNamespace("nnet", quietly = TRUE)) { learner = mlr3::lrn("classif.nnet") diff --git a/man/mlr_learners_regr.nnet.Rd b/man/mlr_learners_regr.nnet.Rd index bc6e3415..50bfb588 100644 --- a/man/mlr_learners_regr.nnet.Rd +++ b/man/mlr_learners_regr.nnet.Rd @@ -25,7 +25,7 @@ lrn("regr.nnet") \itemize{ \item Task type: \dQuote{regr} \item Predict Types: \dQuote{response} -\item Feature Types: \dQuote{numeric}, \dQuote{factor}, \dQuote{ordered} +\item Feature Types: \dQuote{integer}, \dQuote{numeric}, \dQuote{factor}, \dQuote{ordered} \item Required Packages: \CRANpkg{mlr3}, \CRANpkg{mlr3learners}, \CRANpkg{nnet} } } @@ -49,6 +49,7 @@ lrn("regr.nnet") skip \tab logical \tab FALSE \tab TRUE, FALSE \tab - \cr subset \tab untyped \tab - \tab \tab - \cr trace \tab logical \tab TRUE \tab TRUE, FALSE \tab - \cr + formula \tab untyped \tab - \tab \tab - \cr } } @@ -63,6 +64,13 @@ lrn("regr.nnet") } } +\section{Custom mlr3 parameters}{ + +\itemize{ +\item \code{formula}: if not provided, the formula is set to \code{task$formula()}. +} +} + \examples{ if (requireNamespace("nnet", quietly = TRUE)) { learner = mlr3::lrn("regr.nnet")