Skip to content

Commit 9fc73fb

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

21 files changed

+160
-101
lines changed

.editorconfig

+1-1
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

+1-2
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", , "[email protected]", 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

+3-6
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

+23-11
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

+5-1
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

+6-1
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

+5
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

+1-1
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

+5-1
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

+4
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
)

README.Rmd

+2-2
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ Learners which support the extraction feature importance scores can be combined
1515

1616
<!-- badges: start -->
1717
[![r-cmd-check](https://github.com/mlr-org/mlr3filters/actions/workflows/r-cmd-check.yml/badge.svg)](https://github.com/mlr-org/mlr3filters/actions/workflows/r-cmd-check.yml)
18-
[![CodeFactor](https://www.codefactor.io/repository/github/mlr-org/mlr3filters/badge)](https://www.codefactor.io/repository/github/mlr-org/mlr3filters)
18+
[![CRAN Status](https://www.r-pkg.org/badges/version-ago/mlr3filters)](https://cran.r-project.org/package=mlr3filters)
1919
[![StackOverflow](https://img.shields.io/badge/stackoverflow-mlr3-orange.svg)](https://stackoverflow.com/questions/tagged/mlr3)
2020
[![Mattermost](https://img.shields.io/badge/chat-mattermost-orange.svg)](https://lmmisld-lmu-stats-slds.srv.mwn.de/mlr_invite/)
2121
<!-- badges: end -->
@@ -45,7 +45,7 @@ library("mlr3filters")
4545
4646
task = tsk("sonar")
4747
filter = flt("auc")
48-
as.data.table(filter$calculate(task))
48+
head(as.data.table(filter$calculate(task)))
4949
```
5050

5151
### Implemented Filters

README.md

+10-64
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@ from this package for embedded feature selection.
1818
<!-- badges: start -->
1919

2020
[![r-cmd-check](https://github.com/mlr-org/mlr3filters/actions/workflows/r-cmd-check.yml/badge.svg)](https://github.com/mlr-org/mlr3filters/actions/workflows/r-cmd-check.yml)
21-
[![CodeFactor](https://www.codefactor.io/repository/github/mlr-org/mlr3filters/badge)](https://www.codefactor.io/repository/github/mlr-org/mlr3filters)
21+
[![CRAN
22+
Status](https://www.r-pkg.org/badges/version-ago/mlr3filters)](https://cran.r-project.org/package=mlr3filters)
2223
[![StackOverflow](https://img.shields.io/badge/stackoverflow-mlr3-orange.svg)](https://stackoverflow.com/questions/tagged/mlr3)
2324
[![Mattermost](https://img.shields.io/badge/chat-mattermost-orange.svg)](https://lmmisld-lmu-stats-slds.srv.mwn.de/mlr_invite/)
2425
<!-- badges: end -->
@@ -48,71 +49,16 @@ library("mlr3filters")
4849

4950
task = tsk("sonar")
5051
filter = flt("auc")
51-
as.data.table(filter$calculate(task))
52+
head(as.data.table(filter$calculate(task)))
5253
```
5354

54-
## feature score
55-
## 1: V11 0.281136807
56-
## 2: V12 0.242918176
57-
## 3: V10 0.232701774
58-
## 4: V49 0.231262190
59-
## 5: V9 0.230844246
60-
## 6: V48 0.206278443
61-
## 7: V13 0.204699545
62-
## 8: V51 0.199359153
63-
## 9: V47 0.197408749
64-
## 10: V52 0.188028234
65-
## 11: V46 0.187053032
66-
## 12: V45 0.172703631
67-
## 13: V4 0.165227083
68-
## 14: V36 0.165180645
69-
## 15: V5 0.153710411
70-
## 16: V1 0.152317266
71-
## 17: V44 0.151063435
72-
## 18: V21 0.144469211
73-
## 19: V35 0.141450729
74-
## 20: V8 0.141032785
75-
## 21: V43 0.140893471
76-
## 22: V37 0.128076530
77-
## 23: V6 0.124640104
78-
## 24: V20 0.123572026
79-
## 25: V2 0.122782576
80-
## 26: V50 0.121807374
81-
## 27: V3 0.116513421
82-
## 28: V14 0.114748769
83-
## 29: V22 0.113680691
84-
## 30: V58 0.098402526
85-
## 31: V42 0.091436798
86-
## 32: V34 0.090275843
87-
## 33: V23 0.085632024
88-
## 34: V7 0.085074765
89-
## 35: V28 0.078944924
90-
## 36: V31 0.078341228
91-
## 37: V19 0.077366026
92-
## 38: V53 0.071607690
93-
## 39: V54 0.068031949
94-
## 40: V56 0.060648277
95-
## 41: V39 0.058094177
96-
## 42: V33 0.056793907
97-
## 43: V24 0.055447200
98-
## 44: V59 0.054611312
99-
## 45: V27 0.053543234
100-
## 46: V15 0.053264605
101-
## 47: V32 0.043187517
102-
## 48: V16 0.031485093
103-
## 49: V29 0.028605926
104-
## 50: V17 0.026516207
105-
## 51: V41 0.024472927
106-
## 52: V18 0.018621714
107-
## 53: V26 0.017507198
108-
## 54: V38 0.014813783
109-
## 55: V25 0.013838581
110-
## 56: V60 0.012213244
111-
## 57: V30 0.006965729
112-
## 58: V57 0.004876010
113-
## 59: V55 0.003204235
114-
## 60: V40 0.002182595
115-
## feature score
55+
## feature score
56+
## 1: V11 0.2811368
57+
## 2: V12 0.2429182
58+
## 3: V10 0.2327018
59+
## 4: V49 0.2312622
60+
## 5: V9 0.2308442
61+
## 6: V48 0.2062784
11662

11763
### Implemented Filters
11864

man/Filter.Rd

+11
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/mlr_filters_importance.Rd

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/mlr_filters_performance.Rd

+2-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/mlr_filters_relief.Rd

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/mlr_filters_selected_features.Rd

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)