Skip to content
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

Docs #132

Closed
wants to merge 14 commits into from
Closed

Docs #132

Show file tree
Hide file tree
Changes from 11 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
5 changes: 2 additions & 3 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ Suggests:
lgr,
mlr3learners,
mlr3measures,
mlr3proba,
mlr3pipelines,
praznik,
rpart,
testthat (>= 3.0.0),
Expand All @@ -47,15 +47,14 @@ Config/testthat/parallel: true
Encoding: UTF-8
NeedsCompilation: no
Roxygen: list(markdown = TRUE, r6 = TRUE)
RoxygenNote: 7.2.0
RoxygenNote: 7.2.1
Collate:
'Filter.R'
'mlr_filters.R'
'FilterAUC.R'
'FilterAnova.R'
'FilterCMIM.R'
'FilterCarScore.R'
'FilterCarSurvScore.R'
'FilterCorrelation.R'
'FilterDISR.R'
'FilterFindCorrelation.R'
Expand Down
1 change: 0 additions & 1 deletion NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ export(FilterAUC)
export(FilterAnova)
export(FilterCMIM)
export(FilterCarScore)
export(FilterCarSurvScore)
export(FilterCorrelation)
export(FilterDISR)
export(FilterFindCorrelation)
Expand Down
10 changes: 10 additions & 0 deletions R/FilterAUC.R
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,16 @@
#' filter = flt("auc")
#' filter$calculate(task)
#' head(as.data.table(filter), 3)
#'
#' if (requireNamespace("mlr3pipelines")) {
#' library("mlr3pipelines")
#' task = mlr3::tsk("spam")
#'
#' graph = po("filter", filter = flt("auc"), filter.cutoff = 0.1) %>>%
#' po("learner", mlr3::lrn("classif.rpart"))
#'
#' graph$train(task)
#' }
FilterAUC = R6Class("FilterAUC",
inherit = Filter,

Expand Down
10 changes: 10 additions & 0 deletions R/FilterAnova.R
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,16 @@
#'
#' # transform to p-value
#' 10^(-filter$scores)
#'
#' if (requireNamespace("mlr3pipelines")) {
#' library("mlr3pipelines")
#' task = mlr3::tsk("spam")
#'
#' graph = po("filter", filter = flt("anova"), filter.cutoff = 20) %>>%
#' po("learner", mlr3::lrn("classif.rpart"))
#'
#' graph$train(task)
#' }
FilterAnova = R6Class("FilterAnova",
inherit = Filter,

Expand Down
20 changes: 16 additions & 4 deletions R/FilterCMIM.R
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,22 @@
#' @template seealso_filter
#' @export
#' @examples
#' task = mlr3::tsk("iris")
#' filter = flt("cmim")
#' filter$calculate(task, nfeat = 2)
#' as.data.table(filter)
#' if (requireNamespace("praznik")) {
#' task = mlr3::tsk("iris")
#' filter = flt("cmim")
#' filter$calculate(task, nfeat = 2)
#' as.data.table(filter)
#' }
#'
#' if (requireNamespace("mlr3pipelines") && requireNamespace("praznik")) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd favor using mlr3misc::require_namespaces(c("mlr3pipelines", "praznik")) in cases with n > 1.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fine for me.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

but it needs argument quietly = TRUE then 😞

#' library("mlr3pipelines")
#' task = mlr3::tsk("spam")
#'
#' graph = po("filter", filter = flt("cmim"), filter.cutoff = 0.5) %>>%
#' po("learner", mlr3::lrn("classif.rpart"))
#'
#' graph$train(task)
#' }
FilterCMIM = R6Class("FilterCMIM",
inherit = Filter,

Expand Down
20 changes: 16 additions & 4 deletions R/FilterCarScore.R
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,28 @@
#' @template seealso_filter
#' @export
#' @examples
#' task = mlr3::tsk("mtcars")
#' filter = flt("carscore")
#' filter$calculate(task)
#' head(as.data.table(filter), 3)
#' if (requireNamespace("care")) {
#' task = mlr3::tsk("mtcars")
#' filter = flt("carscore")
#' filter$calculate(task)
#' head(as.data.table(filter), 3)
#' }
#'
#' ## changing filter settings
#' filter = flt("carscore")
#' filter$param_set$values = list("diagonal" = TRUE)
#' filter$calculate(task)
#' head(as.data.table(filter), 3)
#'
#' if (requireNamespace("mlr3pipelines") && requireNamespace("care")) {
#' library("mlr3pipelines")
#' task = mlr3::tsk("mtcars")
#'
#' graph = po("filter", filter = flt("carscore"), filter.cutoff = 0.2) %>>%
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd avoid setting filter.cutoff as users might takes this as a "good default" then as its listed in an example.

I see you're setting a different value in each example. Should we calculate a random dynamic value and add a comment that this value should be tuned in practice?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Adding a comment that this value should be tuned: 👍

I don't think a random value is helping, this is just confusing.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think a random value is helping, this is just confusing.

Agree, this might not be obvious. Maybe the combination of a hardcoded value across all examples and a comment about the tuning need might be the best middle way.

#' po("learner", mlr3::lrn("regr.rpart"))
#'
#' graph$train(task)
#' }
FilterCarScore = R6Class("FilterCarScore",
inherit = Filter,

Expand Down
63 changes: 0 additions & 63 deletions R/FilterCarSurvScore.R

This file was deleted.

9 changes: 9 additions & 0 deletions R/FilterCorrelation.R
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,15 @@
#' filter$param_set$values = list("method" = "spearman")
#' filter$calculate(task)
#' as.data.table(filter)
#' if (requireNamespace("mlr3pipelines")) {
#' library("mlr3pipelines")
#' task = mlr3::tsk("boston_housing")
#'
#' graph = po("filter", filter = flt("correlation"), filter.cutoff = 0.2) %>>%
#' po("learner", mlr3::lrn("regr.rpart"))
#'
#' graph$train(task)
#' }
FilterCorrelation = R6Class("FilterCorrelation",
inherit = Filter,

Expand Down
20 changes: 16 additions & 4 deletions R/FilterDISR.R
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,22 @@
#' @template seealso_filter
#' @export
#' @examples
#' task = mlr3::tsk("iris")
#' filter = flt("disr")
#' filter$calculate(task)
#' as.data.table(filter)
#' if (requireNamespace("praznik")) {
#' task = mlr3::tsk("iris")
#' filter = flt("disr")
#' filter$calculate(task)
#' as.data.table(filter)
#' }
#'
#' if (requireNamespace("mlr3pipelines") && requireNamespace("praznik")) {
#' library("mlr3pipelines")
#' task = mlr3::tsk("spam")
#'
#' graph = po("filter", filter = flt("disr"), filter.cutoff = 0.2) %>>%
#' po("learner", mlr3::lrn("classif.rpart"))
#'
#' graph$train(task)
#' }
FilterDISR = R6Class("FilterDISR",
inherit = Filter,

Expand Down
12 changes: 11 additions & 1 deletion R/FilterFindCorrelation.R
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
#' @template seealso_filter
#' @export
#' @examples
#' ## Pearson (default)
#' # Pearson (default)
#' task = mlr3::tsk("mtcars")
#' filter = flt("find_correlation")
#' filter$calculate(task)
Expand All @@ -29,6 +29,16 @@
#' filter = flt("find_correlation", method = "spearman")
#' filter$calculate(task)
#' as.data.table(filter)
#'
#' if (requireNamespace("mlr3pipelines")) {
#' library("mlr3pipelines")
#' task = mlr3::tsk("spam")
#'
#' graph = po("filter", filter = flt("find_correlation"), filter.cutoff = 0.4) %>>%
#' po("learner", mlr3::lrn("classif.rpart"))
#'
#' graph$train(task)
#' }
FilterFindCorrelation = R6Class("FilterFindCorrelation",
inherit = Filter,

Expand Down
26 changes: 21 additions & 5 deletions R/FilterImportance.R
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,27 @@
#' @template seealso_filter
#' @export
#' @examples
#' task = mlr3::tsk("iris")
#' learner = mlr3::lrn("classif.rpart")
#' filter = flt("importance", learner = learner)
#' filter$calculate(task)
#' as.data.table(filter)
#' if (requireNamespace("MASS")) {
#' task = mlr3::tsk("iris")
#' learner = mlr3::lrn("classif.rpart")
#' filter = flt("importance", learner = learner)
#' filter$calculate(task)
#' as.data.table(filter)
#' }
#'
#' if (requireNamespace("mlr3pipelines") && requireNamespace("mlr3learners") &&
#' requireNamespace("MASS")) {
#' library("mlr3learners")
#' library("mlr3pipelines")
#' task = mlr3::tsk("spam")
#'
#' learner = mlr3::lrn("classif.rpart")
#'
#' graph = po("filter", filter = flt("importance", learner = learner), filter.cutoff = 100) %>>%
#' po("learner", mlr3::lrn("classif.lda"))
#'
#' graph$train(task)
#' }
FilterImportance = R6Class("FilterImportance",
inherit = Filter,

Expand Down
36 changes: 25 additions & 11 deletions R/FilterInformationGain.R
Original file line number Diff line number Diff line change
Expand Up @@ -15,19 +15,33 @@
#' @template seealso_filter
#' @export
#' @examples
#' ## InfoGain (default)
#' task = mlr3::tsk("pima")
#' filter = flt("information_gain")
#' filter$calculate(task)
#' head(filter$scores, 3)
#' as.data.table(filter)
#' if (requireNamespace("FSelectorRcpp")) {
#' ## InfoGain (default)
#' task = mlr3::tsk("pima")
#' filter = flt("information_gain")
#' filter$calculate(task)
#' head(filter$scores, 3)
#' as.data.table(filter)
#'
#' ## GainRatio
#' ## GainRatio
#'
#' filterGR = flt("information_gain")
#' filterGR$param_set$values = list("type" = "gainratio")
#' filterGR$calculate(task)
#' head(as.data.table(filterGR), 3)
#' filterGR = flt("information_gain")
#' filterGR$param_set$values = list("type" = "gainratio")
#' filterGR$calculate(task)
#' head(as.data.table(filterGR), 3)
#'
#' }
#'
#' if (requireNamespace("mlr3pipelines") && requireNamespace("FSelectorRcpp")) {
#' library("mlr3pipelines")
#' task = mlr3::tsk("spam")
#'
#' graph = po("filter", filter = flt("information_gain"), filter.cutoff = 0.1) %>>%
#' po("learner", mlr3::lrn("classif.rpart"))
#'
#' graph$train(task)
#'
#' }
FilterInformationGain = R6Class("FilterInformationGain",
inherit = Filter,

Expand Down
20 changes: 16 additions & 4 deletions R/FilterJMI.R
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,22 @@
#' @template seealso_filter
#' @export
#' @examples
#' task = mlr3::tsk("iris")
#' filter = flt("jmi")
#' filter$calculate(task, nfeat = 2)
#' as.data.table(filter)
#' if (requireNamespace("praznik")) {
#' task = mlr3::tsk("iris")
#' filter = flt("jmi")
#' filter$calculate(task, nfeat = 2)
#' as.data.table(filter)
#' }
#'
#' if (requireNamespace("mlr3pipelines") && requireNamespace("praznik")) {
#' library("mlr3pipelines")
#' task = mlr3::tsk("spam")
#'
#' graph = po("filter", filter = flt("jmi"), filter.cutoff = 0.2) %>>%
#' po("learner", mlr3::lrn("classif.rpart"))
#'
#' graph$train(task)
#' }
FilterJMI = R6Class("FilterJMI",
inherit = Filter,

Expand Down
21 changes: 17 additions & 4 deletions R/FilterJMIM.R
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,23 @@
#' @template seealso_filter
#' @export
#' @examples
#' task = mlr3::tsk("iris")
#' filter = flt("jmim")
#' filter$calculate(task, nfeat = 2)
#' as.data.table(filter)
#' if (requireNamespace("praznik")) {
#' task = mlr3::tsk("iris")
#' filter = flt("jmim")
#' filter$calculate(task, nfeat = 2)
#' as.data.table(filter)
#' }
#'
#'
#' if (requireNamespace("mlr3pipelines") && requireNamespace("praznik")) {
#' library("mlr3pipelines")
#' task = mlr3::tsk("spam")
#'
#' graph = po("filter", filter = flt("jmim"), filter.cutoff = 0.5) %>>%
#' po("learner", mlr3::lrn("classif.rpart"))
#'
#' graph$train(task)
#' }
FilterJMIM = R6Class("FilterJMIM",
inherit = Filter,

Expand Down
Loading