Skip to content

Commit

Permalink
docs: rewrite examples (#305)
Browse files Browse the repository at this point in the history
  • Loading branch information
Brandonxzl authored Aug 22, 2024
1 parent 10672b8 commit 8ed7653
Show file tree
Hide file tree
Showing 175 changed files with 2,749 additions and 1,720 deletions.
7 changes: 3 additions & 4 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,14 @@ Authors@R: c(
Description: Extra learners for use in mlr3.
License: LGPL-3
Depends:
R (>= 3.1.0)
R (>= 3.1.0),
mlr3 (>= 0.20.2)
Imports:
checkmate,
data.table,
methods,
mlr3 (>= 0.13.4),
mlr3misc (>= 0.9.4),
paradox,
paradox (>= 1.0.1),
R6
Suggests:
abess,
Expand Down Expand Up @@ -77,7 +77,6 @@ Suggests:
mvtnorm,
nnet,
np,
obliqueRSF,
param6,
partykit,
penalized,
Expand Down
2 changes: 0 additions & 2 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -116,15 +116,13 @@ export(LearnerSurvLearnerSurvBART)
export(LearnerSurvLogisticHazard)
export(LearnerSurvMBoost)
export(LearnerSurvNelson)
export(LearnerSurvObliqueRSF)
export(LearnerSurvPCHazard)
export(LearnerSurvParametric)
export(LearnerSurvPenalized)
export(LearnerSurvPriorityLasso)
export(LearnerSurvRandomForestSRC)
export(LearnerSurvRanger)
export(LearnerSurvSVM)
export(LearnerSurvXgboost)
export(LearnerSurvXgboostAFT)
export(LearnerSurvXgboostCox)
export(create_learner)
Expand Down
5 changes: 5 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,12 @@
and `lrn("surv.xgboost.cox")`.
* Added early stopping and validation to catboost and lightgbm.
* Added missing `case.depth` parameter to `rfsrc` learners.
* `mlr3` is now in Depends instead of Imports.
* Deprecated learner `lrn("surv.xgboost")` was now removed.
Use `lrn("surv.xgboost.cox")` or `lrn("surv.xgboost.aft")` instead.
* Change xgboost default nrounds from 1 to 1000.
* remove obliqueRSF Learner which was long superseded by aorsf
* a lot of examples were added to the learners

# mlr3extralearners 0.8.0

Expand Down
9 changes: 2 additions & 7 deletions R/create_learner.R
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,6 @@
#' Defaults to `"Unknown"`.
#' @param label (`character(1)`)\cr
#' Label for the learner, default is the value of the parameter `algorithm`.
#' @param data_formats (`character(1)`)\cr
#' The data format the learner can deal with (see `mlr_reflections$data_formats`).
#' Default is `"data.table"` and this rarely has to be changes.
#'
#' @examples
#' \dontrun{
Expand All @@ -56,14 +53,13 @@
#' predict_types = c("response", "prob"),
#' properties = c("importance", "missings", "multiclass", "twoclass", "weights"),
#' gh_name = "RaphaelS1",
#' label = "Regression and Partition Tree",
#' data_formats = "data.table"
#' label = "Regression and Partition Tree"
#' )
#' }
#' @export
create_learner = function(path = ".", classname, type, key = tolower(classname), algorithm,
package, caller,
feature_types, predict_types, properties, gh_name = "Unknown", label = toproper(algorithm), data_formats = "data.table") {
feature_types, predict_types, properties, gh_name = "Unknown", label = toproper(algorithm)) {

path = normalizePath(path)
assert_true(dir.exists(path))
Expand Down Expand Up @@ -95,7 +91,6 @@ create_learner = function(path = ".", classname, type, key = tolower(classname),
assert_character(gh_name, any.missing = FALSE, len = 1)
assert_character(label, any.missing = FALSE, len = 1L)

assert_choice(data_formats, mlr3::mlr_reflections$data_formats)
Type = toproper(type)

assert_character(classname, any.missing = FALSE, len = 1)
Expand Down
4 changes: 0 additions & 4 deletions R/fn_list_mlr3learners.R
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,6 @@
#' @param select `character()` \cr Passed to [data.table::subset].
#' @param filter `list()` \cr Named list of conditions to filter on, names correspond to column
#' names in table.
#' @examples
#' list_mlr3learners(
#' select = c("id", "properties", "predict_types"),
#' filter = list(class = "surv", predict_types = "distr"))
#' @export
list_mlr3learners = function(select = NULL, filter = NULL) {
require_namespaces(c("mlr3learners", "mlr3proba", "mlr3cluster"), quietly = TRUE)
Expand Down
2 changes: 1 addition & 1 deletion R/learner_BART_surv_bart.R
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
#' `r format_bib("sparapani2021nonparametric", "chipman2010bart")`
#'
#' @template seealso_learner
#' @template example
#' @template simple_example
#' @export
LearnerSurvLearnerSurvBART = R6Class("LearnerSurvLearnerSurvBART",
inherit = mlr3proba::LearnerSurv,
Expand Down
8 changes: 7 additions & 1 deletion R/learner_CoxBoost_surv_cv_coxboost.R
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,14 @@
#' `r format_bib("binder2009boosting")`
#'
#' @template seealso_learner
#' @template example
#' @export
#' @examplesIf mlr3misc::require_namespaces(c("coin", "sandwich", "partykit"), quietly = TRUE)
#' task = tsk("rats")
#' task$col_roles$feature = c("litter", "rx")
#' learner = lrn("surv.cv_coxboost", maxstepno = 20)
#' splits = partition(task)
#' learner$train(task, splits$train)
#' pred = learner$predict(task, splits$test)
LearnerSurvCVCoxboost = R6Class("LearnerSurvCVCoxboost",
inherit = mlr3proba::LearnerSurv,

Expand Down
25 changes: 24 additions & 1 deletion R/learner_catboost_classif_catboost.R
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,30 @@
#'
#' @export
#' @template seealso_learner
#' @template example
#' @examplesIf mlr3misc::require_namespaces("catboost", quietly = TRUE)
#' # Define the Learner
#' learner = mlr3::lrn("classif.catboost",
#' iterations = 100)
#'
#' print(learner)
#'
#' # Define a Task
#' task = tsk("sonar")
#'
#' # Create train and test set
#' ids = mlr3::partition(task)
#'
#' # Train the learner on the training ids
#' learner$train(task, row_ids = ids$train)
#'
#' print(learner$model)
#' print(learner$importance)
#'
#' # Make predictions for the test rows
#' predictions = learner$predict(task, row_ids = ids$test)
#'
#' # Score the predictions
#' predictions$score()
LearnerClassifCatboost = R6Class("LearnerClassifCatboost",
inherit = LearnerClassif,
public = list(
Expand Down
2 changes: 1 addition & 1 deletion R/learner_flexsurv_surv_flexible.R
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
#' `r format_bib("royston2002flexible")`
#'
#' @template seealso_learner
#' @template example
#' @template simple_example
#' @export
LearnerSurvFlexible = R6Class("LearnerSurvFlexible",
inherit = mlr3proba::LearnerSurv,
Expand Down
5 changes: 4 additions & 1 deletion R/learner_gbm_regr_gbm.R
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,10 @@
#'
#' @export
#' @template seealso_learner
#' @template example
#' @examples
#' # Define the Learner
#' learner = lrn("regr.gbm")
#' print(learner)
LearnerRegrGBM = R6Class("LearnerRegrGBM",
inherit = LearnerRegr,
public = list(
Expand Down
2 changes: 0 additions & 2 deletions R/learner_lightgbm_classif_lightgbm.R
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@
#' Calls [lightgbm::lightgbm()] from \CRANpkg{lightgbm}.
#' The list of parameters can be found [here](https://lightgbm.readthedocs.io/en/latest/Parameters.html#)
#' and in the documentation of [lightgbm::lgb.train()].
#' Note that lightgbm models have to be saved using `lightgbm::lgb.save`, so you cannot simpliy
#' save the learner using `saveRDS`. This will change in future versions of lightgbm.
#'
#' @template learner
#' @templateVar id classif.lightgbm
Expand Down
2 changes: 0 additions & 2 deletions R/learner_lightgbm_regr_lightgbm.R
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@
#' Calls [lightgbm::lightgbm()] from \CRANpkg{lightgbm}.
#' The list of parameters can be found [here](https://lightgbm.readthedocs.io/en/latest/Parameters.html#)
#' and in the documentation of [lightgbm::lgb.train()].
#' Note that lightgbm models have to be saved using `lightgbm::lgb.save`, so you cannot simpliy
#' save the learner using `saveRDS`. This will change in future versions of lightgbm.
#'
#' @template learner
#' @templateVar id regr.lightgbm
Expand Down
15 changes: 14 additions & 1 deletion R/learner_lme4_classif_glmer.R
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,20 @@
#' `r format_bib("bates2010lme4")`
#'
#' @template seealso_learner
#' @template example
#' @examplesIf requireNamespace("lme4", quietly = TRUE)
#'
#' # Define the Learner and set parameter values
#' learner = lrn("classif.glmer",
#' formula = credit_risk ~ (1 | credit_history) + job + property + telephone + savings)
#'
#' # Define a Task
#' task = tsk("german_credit")
#' task$select(c("credit_history", "job", "property", "telephone", "savings"))
#'
#' # Train the learner
#' learner$train(task)
#'
#' print(learner$model)
#' @export
LearnerClassifGlmer = R6Class("LearnerClassifGlmer",
inherit = LearnerClassif,
Expand Down
10 changes: 9 additions & 1 deletion R/learner_lme4_regr_lmer.R
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,15 @@
#' `r format_bib("bates2010lme4")`
#'
#' @template seealso_learner
#' @template example
#' @examplesIf requireNamespace("lme4", quietly = TRUE)
#' # Define the Learner and set parameter values
#' learner = lrn("regr.lmer", formula = cmedv ~ (1 | town))
#'
#' # Define a Task
#' task = tsk("boston_housing")
#'
#' learner$train(task)
#' print(learner$model)
#' @export
LearnerRegrLmer = R6Class("LearnerRegrLmer",
inherit = LearnerRegr,
Expand Down
4 changes: 3 additions & 1 deletion R/learner_mboost_regr_gamboost.R
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@
#'
#' @export
#' @template seealso_learner
#' @template example
#' @examples
#' learner = lrn("regr.gamboost", baselearner = "bols")
#' learner
LearnerRegrGAMBoost = R6Class("LearnerRegrGAMBoost",
inherit = LearnerRegr,
public = list(
Expand Down
3 changes: 2 additions & 1 deletion R/learner_mboost_surv_gamboost.R
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@
#'
#' @export
#' @template seealso_learner
#' @template example
#' @examples
#' @template simple_example
LearnerSurvGAMBoost = R6Class("LearnerSurvGAMBoost",
inherit = mlr3proba::LearnerSurv,
public = list(
Expand Down
3 changes: 2 additions & 1 deletion R/learner_mboost_surv_mboost.R
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@
#'
#' @export
#' @template seealso_learner
#' @template example
#' @template simple_example
#' @export
LearnerSurvMBoost = R6Class("LearnerSurvMBoost",
inherit = mlr3proba::LearnerSurv,
public = list(
Expand Down
7 changes: 4 additions & 3 deletions R/learner_mgcv_classif_gam.R
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,12 @@
#' `r format_bib("hastie2017generalized", "wood2012mgcv")`
#'
#' @examples
#'
#' # simple example
#' t = mlr3::tsk("spam")
#' t = mlr3::tsk("spam")$filter(1:1000)
#' l = mlr3::lrn("classif.gam")
#' l$param_set$values$formula = type ~ s(george) + s(charDollar) + s(edu) + ti(george, edu)
#' l$param_set$set_values(
#' formula = type ~ s(george, k = 3) + s(charDollar, k = 3) + s(edu)
#' ')
#' l$train(t)
#' l$model
#' @export
Expand Down
111 changes: 0 additions & 111 deletions R/learner_obliqueRSF_surv_obliqueRSF.R

This file was deleted.

Loading

0 comments on commit 8ed7653

Please sign in to comment.