|
23 | 23 | #' @template seealso_filter
|
24 | 24 | #' @export
|
25 | 25 | #' @examples
|
26 |
| -#' if (mlr3misc::require_namespaces(c("mlr3", "mlr3proba", "mlr3pipelines"), quietly = TRUE)) { |
27 |
| -#' library(mlr3) |
28 |
| -#' library(mlr3proba) |
29 |
| -#' library(mlr3pipelines) |
30 | 26 | #'
|
31 |
| -#' # encode `sex` (two-level factor) |
32 |
| -#' task = tsk("rats") |
33 |
| -#' enc = po("encode", method = "treatment") |
34 |
| -#' task = enc$train(list(task))[[1L]] |
| 27 | +#' filter = flt("univariate_cox") |
| 28 | +#' filter |
35 | 29 | #'
|
36 |
| -#' # simple filter use |
37 |
| -#' filter = flt("univariate_cox") |
38 |
| -#' filter$calculate(task) |
39 |
| -#' as.data.table(filter) |
40 |
| -#' |
41 |
| -#' # transform to p-value |
42 |
| -#' 10^(-filter$scores) |
43 |
| -#' |
44 |
| -#' # Use filter in a learner pipeline |
45 |
| -#' # Note: `filter.cutoff` is selected randomly and should be tuned. |
46 |
| -#' # The significance level of `0.05` serves as a conventional threshold. |
47 |
| -#' # The filter returns the `-log10`-transformed scores so we transform |
48 |
| -#' # the cutoff as well: |
49 |
| -#' cutoff = -log10(0.05) # ~1.3 |
50 |
| -#' |
51 |
| -#' graph = |
52 |
| -#' po("filter", filter = flt("univariate_cox"), filter.cutoff = cutoff) %>>% |
53 |
| -#' po("learner", lrn("surv.coxph")) |
54 |
| -#' learner = as_learner(graph) |
55 |
| -#' |
56 |
| -#' learner$train(task) |
57 |
| -#' |
58 |
| -#' # univariate cox filter scores |
59 |
| -#' learner$model$surv.univariate_cox$scores |
60 |
| -#' |
61 |
| -#' # only two features had a score larger than the specified `cutoff` and |
62 |
| -#' # were used to train the CoxPH model |
63 |
| -#' learner$model$surv.coxph$train_task$feature_names |
64 |
| -#' } |
65 | 30 | FilterUnivariateCox = R6Class("FilterUnivariateCox",
|
66 | 31 | inherit = Filter,
|
67 | 32 | public = list(
|
|
0 commit comments