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

Document return type of private .calculate #92

Merged
merged 2 commits into from
Jan 5, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
14 changes: 10 additions & 4 deletions R/Filter.R
Original file line number Diff line number Diff line change
Expand Up @@ -122,11 +122,17 @@ Filter = R6Class("Filter",
#' features to score (see details), and defaults to the number
#' of features in `task`. Loads required packages and then calls
#' `private$.calculate()` of the respective subclass.
#'
#' This private method is is expected to return a numeric vector, uniquely named
#' with (a subset of) feature names. The returned vector may have missing
#' values.
#' Features with missing values as well as features with no calculated
#' score are automatically ranked last, in a random order.
#' If the task has no rows, each feature gets the score `NA`.
#' @param task ([mlr3::Task])\cr
#' [mlr3::Task] to calculate the filter scores for.
#' @param nfeat ([integer()])\cr
#' THe minimum number of features to calculate filter scores for.
#' The minimum number of features to calculate filter scores for.
calculate = function(task, nfeat = NULL) {
task = assert_task(as_task(task),
feature_types = self$feature_types,
Expand All @@ -135,7 +141,7 @@ Filter = R6Class("Filter",

if (task$nrow == 0L) {
self$scores = shuffle(set_names(rep.int(NA_real_, length(fn)), fn))
} else if (length(task$feature_names) == 0L) {
} else if (length(fn) == 0L) {
self$scores = set_names(numeric(), character())
} else {
if (is.null(nfeat)) {
Expand All @@ -149,8 +155,8 @@ Filter = R6Class("Filter",
scores = private$.calculate(task, nfeat)

# check result, re-order with correction for ties
assert_numeric(scores, any.missing = FALSE, names = "unique")
assert_names(names(scores), subset.of = fn)
assert_numeric(scores, any.missing = TRUE, names = "unique")
assert_names(names(scores), type = "unique", subset.of = fn)
scores = insert_named(set_names(rep(NA_real_, length(fn)), fn), scores)
self$scores = scores[order(scores, runif(length(scores)),
decreasing = TRUE, na.last = TRUE)]
Expand Down
8 changes: 7 additions & 1 deletion man/Filter.Rd

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

4 changes: 2 additions & 2 deletions man/mlr3filters-package.Rd

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