Skip to content

Commit

Permalink
chore: release
Browse files Browse the repository at this point in the history
  • Loading branch information
mllg authored Jan 6, 2023
1 parent e60aaa4 commit 9fc73fb
Show file tree
Hide file tree
Showing 21 changed files with 160 additions and 101 deletions.
2 changes: 1 addition & 1 deletion .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
root = true

[*]
charset = utf8
charset = utf-8
end_of_line = lf
insert_final_newline = true
indent_style = space
Expand Down
3 changes: 1 addition & 2 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Package: mlr3filters
Title: Filter Based Feature Selection for 'mlr3'
Version: 0.6.0.9000
Version: 0.7.0
Authors@R: c(
person("Patrick", "Schratz", , "patrick.schratz@gmail.com", role = "aut",
comment = c(ORCID = "0000-0003-0748-6624")),
Expand Down Expand Up @@ -43,7 +43,6 @@ Suggests:
testthat (>= 3.0.0),
withr
Config/testthat/edition: 3
Config/testthat/parallel: true
Encoding: UTF-8
NeedsCompilation: no
Roxygen: list(markdown = TRUE, r6 = TRUE)
Expand Down
9 changes: 3 additions & 6 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
<!-- NEWS.md is maintained by https://cynkra.github.io/fledge, do not edit -->
# mlr3filters 0.7.0

# mlr3filters 0.6.0.9000

## Chore

- do not use deprecated function from mlr3misc
- Features are now checked for missing values to improve error messages (#140)
- Removed deprecated functions
- Use featureless learner in defaults (#124)


Expand Down
34 changes: 23 additions & 11 deletions R/Filter.R
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,8 @@ Filter = R6Class("Filter",
#' 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_) {
param_set = ps(), feature_types = character(), packages = character(), label = NA_character_,
man = NA_character_) {

self$id = assert_string(id)
self$label = assert_string(label, na.ok = TRUE)
Expand All @@ -102,13 +102,9 @@ Filter = R6Class("Filter",
assert_character(task_types, any.missing = FALSE)
}
self$task_types = task_types
self$task_properties = assert_subset(
task_properties,
unlist(mlr_reflections$task_properties, use.names = FALSE))
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$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)
Expand All @@ -126,6 +122,7 @@ Filter = R6Class("Filter",
print = function() {
catn(format(self), if (is.na(self$label)) "" else paste0(": ", self$label))
catn(str_indent("Task Types:", self$task_types))
catn(str_indent("Properties:", self$properties))
catn(str_indent("Task Properties:", self$task_properties))
catn(str_indent("Packages:", self$packages))
catn(str_indent("Feature types:", self$feature_types))
Expand Down Expand Up @@ -162,13 +159,15 @@ Filter = R6Class("Filter",
calculate = function(task, nfeat = NULL) {
task = assert_task(as_task(task),
feature_types = self$feature_types,
task_properties = self$task_properties)
task_properties = self$task_properties
)

fn = task$feature_names

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

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

if (any(task$missings() > 0L)) {
if ("missings" %nin% self$properties && any(task$missings() > 0L)) {
stopf("Cannot apply filter '%s' on task '%s', missing values detected",
self$id, task$id)
}
Expand All @@ -201,6 +200,19 @@ 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()
}
)
)

Expand Down
6 changes: 5 additions & 1 deletion R/FilterImportance.R
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
#' if (mlr3misc::require_namespaces(c("mlr3pipelines", "rpart", "mlr3learners"), quietly = TRUE)) {
#' library("mlr3learners")
#' library("mlr3pipelines")
#' task = mlr3::tsk("spam")
#' task = mlr3::tsk("sonar")
#'
#' learner = mlr3::lrn("classif.rpart")
#'
Expand Down Expand Up @@ -66,6 +66,10 @@ FilterImportance = R6Class("FilterImportance",
learner = self$learner$clone(deep = TRUE)
learner = learner$train(task = task)
learner$base_learner()$importance()
},

.get_properties = function() {
intersect("missings", self$learner$properties)
}
)
)
Expand Down
7 changes: 6 additions & 1 deletion R/FilterPerformance.R
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,10 @@
#' filter$calculate(task)
#' as.data.table(filter)
#' }
#'
#' if (mlr3misc::require_namespaces(c("mlr3pipelines", "rpart"), quietly = TRUE)) {
#' library("mlr3pipelines")
#' task = mlr3::tsk("spam")
#' task = mlr3::tsk("iris")
#' l = lrn("classif.rpart")
#'
#' # Note: `filter.frac` is selected randomly and should be tuned.
Expand Down Expand Up @@ -86,6 +87,10 @@ FilterPerformance = R6Class("FilterPerformance",
}

set_names(perf, fn)
},

.get_properties = function() {
intersect("missings", self$learner$properties)
}
)
)
Expand Down
5 changes: 5 additions & 0 deletions R/FilterPermutation.R
Original file line number Diff line number Diff line change
Expand Up @@ -129,8 +129,13 @@ FilterPermutation = R6Class("FilterPermutation",
}

delta
},

.get_properties = function() {
intersect("missings", self$learner$properties)
}
)

)

#' @include mlr_filters.R
Expand Down
2 changes: 1 addition & 1 deletion R/FilterRelief.R
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
#' @examples
#' if (requireNamespace("FSelectorRcpp")) {
#' ## Relief (default)
#' task = mlr3::tsk("sonar")
#' task = mlr3::tsk("iris")
#' filter = flt("relief")
#' filter$calculate(task)
#' head(filter$scores, 3)
Expand Down
6 changes: 5 additions & 1 deletion R/FilterSelectedFeatures.R
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
#' if (mlr3misc::require_namespaces(c("mlr3pipelines", "mlr3learners", "rpart"), quietly = TRUE)) {
#' library("mlr3pipelines")
#' library("mlr3learners")
#' task = mlr3::tsk("spam")
#' task = mlr3::tsk("sonar")
#'
#' filter = flt("selected_features", learner = lrn("classif.rpart"))
#'
Expand Down Expand Up @@ -75,6 +75,10 @@ FilterSelectedFeatures = R6Class("FilterSelectedFeatures",
learner = learner$train(task = task)
score = named_vector(task$feature_names, init = 0)
replace(score, names(score) %in% learner$selected_features(), 1)
},

.get_properties = function() {
intersect("missings", self$learner$properties)
}
)
)
Expand Down
4 changes: 4 additions & 0 deletions R/FilterVariance.R
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,10 @@ FilterVariance = R6Class("FilterVariance",
.calculate = function(task, nfeat) {
na_rm = self$param_set$values$na.rm %??% TRUE
map_dbl(task$data(cols = task$feature_names), var, na.rm = na_rm)
},

.get_properties = function() {
if (isTRUE(self$param_set$values$na.rm)) "missings" else character()
}
)
)
Expand Down
4 changes: 2 additions & 2 deletions README.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ Learners which support the extraction feature importance scores can be combined

<!-- badges: start -->
[![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)
[![CodeFactor](https://www.codefactor.io/repository/github/mlr-org/mlr3filters/badge)](https://www.codefactor.io/repository/github/mlr-org/mlr3filters)
[![CRAN Status](https://www.r-pkg.org/badges/version-ago/mlr3filters)](https://cran.r-project.org/package=mlr3filters)
[![StackOverflow](https://img.shields.io/badge/stackoverflow-mlr3-orange.svg)](https://stackoverflow.com/questions/tagged/mlr3)
[![Mattermost](https://img.shields.io/badge/chat-mattermost-orange.svg)](https://lmmisld-lmu-stats-slds.srv.mwn.de/mlr_invite/)
<!-- badges: end -->
Expand Down Expand Up @@ -45,7 +45,7 @@ library("mlr3filters")
task = tsk("sonar")
filter = flt("auc")
as.data.table(filter$calculate(task))
head(as.data.table(filter$calculate(task)))
```

### Implemented Filters
Expand Down
74 changes: 10 additions & 64 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ from this package for embedded feature selection.
<!-- badges: start -->

[![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)
[![CodeFactor](https://www.codefactor.io/repository/github/mlr-org/mlr3filters/badge)](https://www.codefactor.io/repository/github/mlr-org/mlr3filters)
[![CRAN
Status](https://www.r-pkg.org/badges/version-ago/mlr3filters)](https://cran.r-project.org/package=mlr3filters)
[![StackOverflow](https://img.shields.io/badge/stackoverflow-mlr3-orange.svg)](https://stackoverflow.com/questions/tagged/mlr3)
[![Mattermost](https://img.shields.io/badge/chat-mattermost-orange.svg)](https://lmmisld-lmu-stats-slds.srv.mwn.de/mlr_invite/)
<!-- badges: end -->
Expand Down Expand Up @@ -48,71 +49,16 @@ library("mlr3filters")

task = tsk("sonar")
filter = flt("auc")
as.data.table(filter$calculate(task))
head(as.data.table(filter$calculate(task)))
```

## feature score
## 1: V11 0.281136807
## 2: V12 0.242918176
## 3: V10 0.232701774
## 4: V49 0.231262190
## 5: V9 0.230844246
## 6: V48 0.206278443
## 7: V13 0.204699545
## 8: V51 0.199359153
## 9: V47 0.197408749
## 10: V52 0.188028234
## 11: V46 0.187053032
## 12: V45 0.172703631
## 13: V4 0.165227083
## 14: V36 0.165180645
## 15: V5 0.153710411
## 16: V1 0.152317266
## 17: V44 0.151063435
## 18: V21 0.144469211
## 19: V35 0.141450729
## 20: V8 0.141032785
## 21: V43 0.140893471
## 22: V37 0.128076530
## 23: V6 0.124640104
## 24: V20 0.123572026
## 25: V2 0.122782576
## 26: V50 0.121807374
## 27: V3 0.116513421
## 28: V14 0.114748769
## 29: V22 0.113680691
## 30: V58 0.098402526
## 31: V42 0.091436798
## 32: V34 0.090275843
## 33: V23 0.085632024
## 34: V7 0.085074765
## 35: V28 0.078944924
## 36: V31 0.078341228
## 37: V19 0.077366026
## 38: V53 0.071607690
## 39: V54 0.068031949
## 40: V56 0.060648277
## 41: V39 0.058094177
## 42: V33 0.056793907
## 43: V24 0.055447200
## 44: V59 0.054611312
## 45: V27 0.053543234
## 46: V15 0.053264605
## 47: V32 0.043187517
## 48: V16 0.031485093
## 49: V29 0.028605926
## 50: V17 0.026516207
## 51: V41 0.024472927
## 52: V18 0.018621714
## 53: V26 0.017507198
## 54: V38 0.014813783
## 55: V25 0.013838581
## 56: V60 0.012213244
## 57: V30 0.006965729
## 58: V57 0.004876010
## 59: V55 0.003204235
## 60: V40 0.002182595
## feature score
## feature score
## 1: V11 0.2811368
## 2: V12 0.2429182
## 3: V10 0.2327018
## 4: V49 0.2312622
## 5: V9 0.2308442
## 6: V48 0.2062784

### Implemented Filters

Expand Down
11 changes: 11 additions & 0 deletions man/Filter.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion man/mlr_filters_importance.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion man/mlr_filters_performance.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion man/mlr_filters_relief.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion man/mlr_filters_selected_features.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 9fc73fb

Please sign in to comment.