Skip to content

Commit 9fc73fb

Browse files
authored
chore: release
1 parent e60aaa4 commit 9fc73fb

21 files changed

+160
-101
lines changed

.editorconfig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
root = true
33

44
[*]
5-
charset = utf8
5+
charset = utf-8
66
end_of_line = lf
77
insert_final_newline = true
88
indent_style = space

DESCRIPTION

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Package: mlr3filters
22
Title: Filter Based Feature Selection for 'mlr3'
3-
Version: 0.6.0.9000
3+
Version: 0.7.0
44
Authors@R: c(
55
person("Patrick", "Schratz", , "patrick.schratz@gmail.com", role = "aut",
66
comment = c(ORCID = "0000-0003-0748-6624")),
@@ -43,7 +43,6 @@ Suggests:
4343
testthat (>= 3.0.0),
4444
withr
4545
Config/testthat/edition: 3
46-
Config/testthat/parallel: true
4746
Encoding: UTF-8
4847
NeedsCompilation: no
4948
Roxygen: list(markdown = TRUE, r6 = TRUE)

NEWS.md

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,7 @@
1-
<!-- NEWS.md is maintained by https://cynkra.github.io/fledge, do not edit -->
1+
# mlr3filters 0.7.0
22

3-
# mlr3filters 0.6.0.9000
4-
5-
## Chore
6-
7-
- do not use deprecated function from mlr3misc
3+
- Features are now checked for missing values to improve error messages (#140)
4+
- Removed deprecated functions
85
- Use featureless learner in defaults (#124)
96

107

R/Filter.R

Lines changed: 23 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -91,8 +91,8 @@ Filter = R6Class("Filter",
9191
#' this object. The referenced help package can be opened via method
9292
#' `$help()`.
9393
initialize = function(id, task_types, task_properties = character(),
94-
param_set = ps(), feature_types = character(),
95-
packages = character(), label = NA_character_, man = NA_character_) {
94+
param_set = ps(), feature_types = character(), packages = character(), label = NA_character_,
95+
man = NA_character_) {
9696

9797
self$id = assert_string(id)
9898
self$label = assert_string(label, na.ok = TRUE)
@@ -102,13 +102,9 @@ Filter = R6Class("Filter",
102102
assert_character(task_types, any.missing = FALSE)
103103
}
104104
self$task_types = task_types
105-
self$task_properties = assert_subset(
106-
task_properties,
107-
unlist(mlr_reflections$task_properties, use.names = FALSE))
105+
self$task_properties = assert_subset(task_properties, unlist(mlr_reflections$task_properties, use.names = FALSE))
108106
self$param_set = assert_param_set(param_set)
109-
self$feature_types = assert_subset(
110-
feature_types,
111-
mlr_reflections$task_feature_types)
107+
self$feature_types = assert_subset(feature_types, mlr_reflections$task_feature_types)
112108
self$packages = assert_character(packages, any.missing = FALSE, min.chars = 1L)
113109
self$scores = set_names(numeric(), character())
114110
self$man = assert_string(man, na.ok = TRUE)
@@ -126,6 +122,7 @@ Filter = R6Class("Filter",
126122
print = function() {
127123
catn(format(self), if (is.na(self$label)) "" else paste0(": ", self$label))
128124
catn(str_indent("Task Types:", self$task_types))
125+
catn(str_indent("Properties:", self$properties))
129126
catn(str_indent("Task Properties:", self$task_properties))
130127
catn(str_indent("Packages:", self$packages))
131128
catn(str_indent("Feature types:", self$feature_types))
@@ -162,13 +159,15 @@ Filter = R6Class("Filter",
162159
calculate = function(task, nfeat = NULL) {
163160
task = assert_task(as_task(task),
164161
feature_types = self$feature_types,
165-
task_properties = self$task_properties)
162+
task_properties = self$task_properties
163+
)
164+
165+
fn = task$feature_names
166166

167167
if (!is_scalar_na(self$task_types) && task$task_type %nin% self$task_types) {
168168
stopf("Filter '%s' does not support the type '%s' of task '%s'",
169169
self$id, task$task_type, task$id)
170170
}
171-
fn = task$feature_names
172171

173172
if (task$nrow == 0L) {
174173
self$scores = shuffle(set_names(rep.int(NA_real_, length(fn)), fn))
@@ -182,7 +181,7 @@ Filter = R6Class("Filter",
182181
nfeat = min(nfeat, length(fn))
183182
}
184183

185-
if (any(task$missings() > 0L)) {
184+
if ("missings" %nin% self$properties && any(task$missings() > 0L)) {
186185
stopf("Cannot apply filter '%s' on task '%s', missing values detected",
187186
self$id, task$id)
188187
}
@@ -201,6 +200,19 @@ Filter = R6Class("Filter",
201200

202201
invisible(self)
203202
}
203+
),
204+
205+
active = list(
206+
#' @field properties ([character()])\cr
207+
#' Properties of the filter. Currently, only `"missings"` is supported.
208+
#' A filter has the property `"missings"`, iff the filter can handle missing values
209+
#' in the features in a graceful way. Otherwise, an assertion is thrown if missing
210+
#' values are detected.
211+
properties = function(rhs) {
212+
assert_ro_binding(rhs)
213+
get_properties = get0(".get_properties", private)
214+
if (is.null(get_properties)) character() else get_properties()
215+
}
204216
)
205217
)
206218

R/FilterImportance.R

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
#' if (mlr3misc::require_namespaces(c("mlr3pipelines", "rpart", "mlr3learners"), quietly = TRUE)) {
2323
#' library("mlr3learners")
2424
#' library("mlr3pipelines")
25-
#' task = mlr3::tsk("spam")
25+
#' task = mlr3::tsk("sonar")
2626
#'
2727
#' learner = mlr3::lrn("classif.rpart")
2828
#'
@@ -66,6 +66,10 @@ FilterImportance = R6Class("FilterImportance",
6666
learner = self$learner$clone(deep = TRUE)
6767
learner = learner$train(task = task)
6868
learner$base_learner()$importance()
69+
},
70+
71+
.get_properties = function() {
72+
intersect("missings", self$learner$properties)
6973
}
7074
)
7175
)

R/FilterPerformance.R

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,10 @@
1919
#' filter$calculate(task)
2020
#' as.data.table(filter)
2121
#' }
22+
#'
2223
#' if (mlr3misc::require_namespaces(c("mlr3pipelines", "rpart"), quietly = TRUE)) {
2324
#' library("mlr3pipelines")
24-
#' task = mlr3::tsk("spam")
25+
#' task = mlr3::tsk("iris")
2526
#' l = lrn("classif.rpart")
2627
#'
2728
#' # Note: `filter.frac` is selected randomly and should be tuned.
@@ -86,6 +87,10 @@ FilterPerformance = R6Class("FilterPerformance",
8687
}
8788

8889
set_names(perf, fn)
90+
},
91+
92+
.get_properties = function() {
93+
intersect("missings", self$learner$properties)
8994
}
9095
)
9196
)

R/FilterPermutation.R

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,8 +129,13 @@ FilterPermutation = R6Class("FilterPermutation",
129129
}
130130

131131
delta
132+
},
133+
134+
.get_properties = function() {
135+
intersect("missings", self$learner$properties)
132136
}
133137
)
138+
134139
)
135140

136141
#' @include mlr_filters.R

R/FilterRelief.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
#' @examples
1212
#' if (requireNamespace("FSelectorRcpp")) {
1313
#' ## Relief (default)
14-
#' task = mlr3::tsk("sonar")
14+
#' task = mlr3::tsk("iris")
1515
#' filter = flt("relief")
1616
#' filter$calculate(task)
1717
#' head(filter$scores, 3)

R/FilterSelectedFeatures.R

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
#' if (mlr3misc::require_namespaces(c("mlr3pipelines", "mlr3learners", "rpart"), quietly = TRUE)) {
3030
#' library("mlr3pipelines")
3131
#' library("mlr3learners")
32-
#' task = mlr3::tsk("spam")
32+
#' task = mlr3::tsk("sonar")
3333
#'
3434
#' filter = flt("selected_features", learner = lrn("classif.rpart"))
3535
#'
@@ -75,6 +75,10 @@ FilterSelectedFeatures = R6Class("FilterSelectedFeatures",
7575
learner = learner$train(task = task)
7676
score = named_vector(task$feature_names, init = 0)
7777
replace(score, names(score) %in% learner$selected_features(), 1)
78+
},
79+
80+
.get_properties = function() {
81+
intersect("missings", self$learner$properties)
7882
}
7983
)
8084
)

R/FilterVariance.R

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,10 @@ FilterVariance = R6Class("FilterVariance",
6161
.calculate = function(task, nfeat) {
6262
na_rm = self$param_set$values$na.rm %??% TRUE
6363
map_dbl(task$data(cols = task$feature_names), var, na.rm = na_rm)
64+
},
65+
66+
.get_properties = function() {
67+
if (isTRUE(self$param_set$values$na.rm)) "missings" else character()
6468
}
6569
)
6670
)

0 commit comments

Comments
 (0)