+
Skip to content
Open
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
3 changes: 2 additions & 1 deletion .lintr
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ linters: linters_with_defaults(
object_name_linter = object_name_linter(c("snake_case", "CamelCase")), # only allow snake case and camel case object names
cyclocomp_linter = NULL, # do not check function complexity
commented_code_linter = NULL, # allow code in comments
line_length_linter = line_length_linter(120)
line_length_linter = line_length_linter(120),
indentation_linter = indentation_linter(indent = 2, hanging_indent_style = "never")
)

5 changes: 5 additions & 0 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,10 @@ Suggests:
survival,
testthat (>= 3.0.0),
withr
Remotes:
mlr-org/mlr3misc@common_baseclass,
mlr-org/mlr3pipelines@common_baseclass,
mlr-org/mlr3@common_baseclass
Config/testthat/edition: 3
Encoding: UTF-8
NeedsCompilation: no
Expand All @@ -71,6 +75,7 @@ Collate:
'FilterJMI.R'
'FilterJMIM.R'
'FilterKruskalTest.R'
'FilterLearnerPerformance.R'
'FilterMIM.R'
'FilterMRMR.R'
'FilterNJMIM.R'
Expand Down
89 changes: 12 additions & 77 deletions R/Filter.R
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,8 @@
#' @family Filter
#' @export
Filter = R6Class("Filter",
inherit = Mlr3Component,
public = list(
#' @field id (`character(1)`)\cr
#' Identifier of the object.
#' Used in tables, plot and text output.
id = NULL,

#' @field label (`character(1)`)\cr
#' Label for this object.
#' Can be used in tables, plot and text output instead of the ID.
label = NA_character_,

#' @field task_types (`character()`)\cr
#' Set of supported task types, e.g. `"classif"` or `"regr"`.
#' Can be set to the scalar value `NA` to allow any task type.
Expand All @@ -39,23 +30,10 @@ Filter = R6Class("Filter",
#' [mlr3::Task]task properties.
task_properties = NULL,

#' @field param_set ([paradox::ParamSet])\cr
#' Set of hyperparameters.
param_set = NULL,

#' @field feature_types (`character()`)\cr
#' Feature types of the filter.
feature_types = NULL,

#' @field packages ([character()])\cr
#' Packages which this filter is relying on.
packages = NULL,

#' @field man (`character(1)`)\cr
#' String in the format `[pkg]::[topic]` pointing to a manual page for this object.
#' Defaults to `NA`, but can be set by child classes.
man = NULL,

#' @field scores
#' Stores the calculated filter score values as named numeric vector.
#' The vector is sorted in decreasing order with possible `NA` values
Expand Down Expand Up @@ -90,31 +68,27 @@ Filter = R6Class("Filter",
#' String in the format `[pkg]::[topic]` pointing to a manual page for
#' this object. The referenced help package can be opened via method
#' `$help()`.
initialize = function(id, task_types, task_properties = character(),
param_set = ps(), feature_types = character(), packages = character(), label = NA_character_,
man = NA_character_) {
initialize = function(id = dict_entry, task_types, task_properties = character(0),
param_set = ps(), feature_types = character(0), packages = character(0),
properties = character(0), label, man, dict_entry = id
) {
if (!missing(label) || !missing(man)) {
mlr3component_deprecation_msg("label and man are deprecated for Filter construction and will be removed in the future.")
}

super$initialize(dict_entry = dict_entry, dict_shortaccess = "flt", id = id,
param_set = param_set, packages = packages, properties = properties)

self$id = assert_string(id)
self$label = assert_string(label, na.ok = TRUE)
if (!test_scalar_na(task_types)) {
# we allow any task type here, otherwise we are not able to construct
# the filter without loading additional packages like mlr3proba
assert_character(task_types, any.missing = FALSE)
}
assert_subset(properties, mlr_reflections$filter_properties) # only allow missings for now
self$task_types = task_types
self$task_properties = assert_subset(task_properties, unlist(mlr_reflections$task_properties, use.names = FALSE))
self$param_set = assert_param_set(param_set)
self$feature_types = assert_subset(feature_types, mlr_reflections$task_feature_types)
self$packages = assert_character(packages, any.missing = FALSE, min.chars = 1L)
self$scores = set_names(numeric(), character())
self$man = assert_string(man, na.ok = TRUE)
},

#' @description
#' Format helper for Filter class
#' @param ... (ignored).
format = function(...) {
sprintf("<%s:%s>", class(self)[1L], self$id) # nocov
},

#' @description
Expand All @@ -133,12 +107,6 @@ Filter = R6Class("Filter",
}
},

#' @description
#' Opens the corresponding help page referenced by field `$man`.
help = function() {
open_help(self$man) # nocov
},

#' @description
#' Calculates the filter score values for the provided [mlr3::Task] and
#' stores them in field `scores`. `nfeat` determines the minimum number of
Expand Down Expand Up @@ -200,39 +168,6 @@ Filter = R6Class("Filter",

invisible(self)
}
),

active = list(
#' @field properties ([character()])\cr
#' Properties of the filter. Currently, only `"missings"` is supported.
#' A filter has the property `"missings"`, iff the filter can handle missing values
#' in the features in a graceful way. Otherwise, an assertion is thrown if missing
#' values are detected.
properties = function(rhs) {
assert_ro_binding(rhs)
get_properties = get0(".get_properties", private)
if (is.null(get_properties)) character() else get_properties()
},

#' @field hash (`character(1)`)\cr
#' Hash (unique identifier) for this object.
hash = function(rhs) {
assert_ro_binding(rhs)
calculate_hash(class(self), self$id, self$param_set$values, mget(private$.extra_hash, envir = self))
},

#' @field phash (`character(1)`)\cr
#' Hash (unique identifier) for this partial object, excluding some components
#' which are varied systematically during tuning (parameter values) or feature
#' selection (feature names).
phash = function(rhs) {
assert_ro_binding(rhs)
calculate_hash(class(self), self$id, mget(private$.extra_hash, envir = self))
}
),

private = list(
.extra_hash = character()
)
)

Expand Down
7 changes: 2 additions & 5 deletions R/FilterAUC.R
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,10 @@ FilterAUC = R6Class("FilterAUC",
#' @description Create a FilterAUC object.
initialize = function() {
super$initialize(
id = "auc",
dict_entry = "auc",
task_types = "classif",
task_properties = "twoclass",
feature_types = c("integer", "numeric"),
packages = "mlr3measures",
label = "Area Under the ROC Curve Score",
man = "mlr3filters::mlr_filters_auc"
feature_types = c("integer", "numeric")
)
}
),
Expand Down
6 changes: 2 additions & 4 deletions R/FilterAnova.R
Original file line number Diff line number Diff line change
Expand Up @@ -47,12 +47,10 @@ FilterAnova = R6Class("FilterAnova",
#' @description Create a FilterAnova object.
initialize = function() {
super$initialize(
id = "anova",
dict_entry = "anova",
packages = "stats",
feature_types = c("integer", "numeric"),
task_types = "classif",
label = "ANOVA F-Test",
man = "mlr3filters::mlr_filters_anova"
task_types = "classif"
)
}
),
Expand Down
12 changes: 4 additions & 8 deletions R/FilterBoruta.R
Original file line number Diff line number Diff line change
Expand Up @@ -49,20 +49,16 @@ FilterBoruta = R6Class("FilterBoruta",
doTrace = p_int(lower = 0, upper = 4, default = 0),
holdHistory = p_lgl(default = TRUE),
getImp = p_uty(),
keep = p_fct(levels = c("confirmed", "tentative"), default = "confirmed"),
num.threads = p_int(lower = 1, default = 1)
keep = p_fct(levels = c("confirmed", "tentative"), tags = "required", init = "confirmed"),
num.threads = p_int(lower = 1, default = 2, init = 1)
)

param_set$set_values(keep = "confirmed", num.threads = 1)

super$initialize(
id = "boruta",
dict_entry = "boruta",
task_types = c("regr", "classif"),
param_set = param_set,
packages = "Boruta",
feature_types = c("integer", "numeric"),
label = "Burota",
man = "mlr3filters::mlr_filters_boruta"
feature_types = c("integer", "numeric")
)
}
),
Expand Down
9 changes: 3 additions & 6 deletions R/FilterCMIM.R
Original file line number Diff line number Diff line change
Expand Up @@ -46,18 +46,15 @@ FilterCMIM = R6Class("FilterCMIM",
#' @description Create a FilterCMIM object.
initialize = function() {
param_set = ps(
threads = p_int(lower = 0L, default = 0L, tags = "threads")
threads = p_int(lower = 0L, default = 0L, tags = "threads", init = 1L)
)
param_set$values = list(threads = 1L)

super$initialize(
id = "cmim",
dict_entry = "cmim",
task_types = c("classif", "regr"),
param_set = param_set,
feature_types = c("integer", "numeric", "factor", "ordered"),
packages = "praznik",
label = "Minimal Conditional Mutual Information Maximization",
man = "mlr3filters::mlr_filters_cmim"
packages = "praznik"
)
}
),
Expand Down
6 changes: 2 additions & 4 deletions R/FilterCarScore.R
Original file line number Diff line number Diff line change
Expand Up @@ -53,13 +53,11 @@ FilterCarScore = R6Class("FilterCarScore",
param_set$values = list(verbose = FALSE)

super$initialize(
id = "carscore",
dict_entry = "carscore",
task_types = "regr",
param_set = param_set,
feature_types = c("logical", "integer", "numeric"),
packages = "care",
label = "Correlation-Adjusted coRrelation Score",
man = "mlr3filters::mlr_filters_carscore"
packages = "care"
)
}
),
Expand Down
6 changes: 2 additions & 4 deletions R/FilterCarSurvScore.R
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,11 @@ FilterCarSurvScore = R6Class("FilterCarSurvScore",
denom = p_fct(c("1/n", "sum_w"), default = "1/n")
)
super$initialize(
id = "surv.carsurvscore",
dict_entry = "carsurvscore",
packages = c("carSurv", "mlr3proba"),
param_set = ps,
feature_types = c("integer", "numeric"),
task_types = "surv",
label = "Correlation-Adjusted coRrelation Survival Score",
man = "mlr3filters::mlr_filters_carsurvscore"
task_types = "surv"
)
}
),
Expand Down
10 changes: 2 additions & 8 deletions R/FilterCorrelation.R
Original file line number Diff line number Diff line change
Expand Up @@ -60,13 +60,12 @@ FilterCorrelation = R6Class("FilterCorrelation",
)

super$initialize(
id = "correlation",
dict_entry = "correlation",
task_types = "regr",
param_set = param_set,
feature_types = c("integer", "numeric"),
packages = "stats",
label = "Correlation",
man = "mlr3filters::mlr_filters_correlation"
properties = "missings"
)
}
),
Expand All @@ -80,12 +79,7 @@ FilterCorrelation = R6Class("FilterCorrelation",
y = as.matrix(task$truth()),
.args = pv)[, 1L]
set_names(abs(score), fn)
},

.get_properties = function() {
"missings"
}

)
)

Expand Down
9 changes: 3 additions & 6 deletions R/FilterDISR.R
Original file line number Diff line number Diff line change
Expand Up @@ -46,18 +46,15 @@ FilterDISR = R6Class("FilterDISR",
#' @description Create a FilterDISR object.
initialize = function() {
param_set = ps(
threads = p_int(lower = 0L, default = 0L, tags = "threads")
threads = p_int(lower = 0L, default = 0L, tags = "threads", init = 1L)
)
param_set$values = list(threads = 1L)

super$initialize(
id = "disr",
dict_entry = "disr",
task_types = c("classif", "regr"),
param_set = param_set,
feature_types = c("integer", "numeric", "factor", "ordered"),
packages = "praznik",
label = "Double Input Symmetrical Relevance",
man = "mlr3filters::mlr_filters_disr"
packages = "praznik"
)
}
),
Expand Down
13 changes: 2 additions & 11 deletions R/FilterFindCorrelation.R
Original file line number Diff line number Diff line change
Expand Up @@ -55,13 +55,12 @@ FilterFindCorrelation = R6Class("FilterFindCorrelation",
)

super$initialize(
id = "find_correlation",
dict_entry = "find_correlation",
task_types = NA_character_,
param_set = param_set,
feature_types = c("integer", "numeric"),
packages = "stats",
label = "Correlation-based Score",
man = "mlr3filters::mlr_filters_find_correlation"
properties = "missings"
)
}
),
Expand Down Expand Up @@ -94,14 +93,6 @@ FilterFindCorrelation = R6Class("FilterFindCorrelation",
# The following has the correct names and values, BUT we need scores in
# reverse order. Shift by 1 to get positive values.
1 - apply(cm, 2, max)
},
.get_properties = function() {
use = self$param_set$values$use %??% "everything"
if (use %in% c("complete.obs", "pairwise.complete.obs")) {
"missings"
} else {
character(0)
}
}
)
)
Expand Down
Loading
Loading
点击 这是indexloc提供的php浏览器服务,不要输入任何密码和下载