+
Skip to content
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@ Suggests:
mlr3proba,
praznik,
rpart,
testthat (>= 3.0.0)
testthat (>= 3.0.0),
withr
Config/testthat/edition: 3
Config/testthat/parallel: true
Encoding: UTF-8
Expand Down
51 changes: 37 additions & 14 deletions R/Filter.R
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,6 @@
#' unimportant features get a small value. Note that filter scores may also be
#' negative.
#'
#' @template field_id
#' @template field_task_type
#' @template field_task_properties
#' @template field_param_set
#' @template field_feature_types
#' @template field_packages
#'
#' @details
#' Some features support partial scoring of the feature set:
#' If `nfeat` is not `NULL`, only the best `nfeat` features are guaranteed to
Expand All @@ -24,11 +17,38 @@
#' @export
Filter = R6Class("Filter",
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_type (`character(1)`)\cr
#' Task type, e.g. `"classif"` or `"regr"`.
#' Can be set to `NA` to allow all task types.
#'
#' For a complete list of possible task types (depending on the loaded packages),
#' see [`mlr_reflections$task_types$type`][mlr_reflections].
task_type = NULL,

#' @field task_properties (`character()`)\cr
#' [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
Expand Down Expand Up @@ -64,15 +84,18 @@ Filter = R6Class("Filter",
#' Set of required packages.
#' Note that these packages will be loaded via [requireNamespace()], and
#' are not attached.
#' @param label (`character(1)`)\cr
#' Label for the new instance.
#' @param man (`character(1)`)\cr
#' 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_type, task_properties = character(),
param_set = ps(), feature_types = character(),
packages = character(), man = NA_character_) {
packages = character(), label = NA_character_, man = NA_character_) {

self$id = assert_string(id)
self$label = assert_string(label, na.ok = TRUE)
if (!test_scalar_na(task_type)) {
# we allow any task type here, otherwise we are not able to construct
# the filter without loading additional packages like mlr3proba
Expand Down Expand Up @@ -103,15 +126,15 @@ Filter = R6Class("Filter",
#' @description
#' Printer for Filter class
print = function() {
catf(format(self)) # nocov start
catf(str_indent("Task Types:", self$task_type))
catf(str_indent("Task Properties:", self$task_properties))
catf(str_indent("Packages:", self$packages))
catf(str_indent("Feature types:", self$feature_types))
catn(format(self), if (is.na(self$label)) "" else paste0(": ", self$label))
catn(str_indent("Task Types:", self$task_type))
catn(str_indent("Task Properties:", self$task_properties))
catn(str_indent("Packages:", self$packages))
catn(str_indent("Feature types:", self$feature_types))
if (length(self$scores)) {
print(as.data.table(self),
nrows = 10L, topn = 5L, class = FALSE,
row.names = TRUE, print.keys = FALSE) # nocov end
row.names = TRUE, print.keys = FALSE)
}
},

Expand Down
1 change: 1 addition & 0 deletions R/FilterAUC.R
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ FilterAUC = R6Class("FilterAUC",
task_properties = "twoclass",
feature_types = c("integer", "numeric"),
packages = "mlr3measures",
label = "Area Under the ROC Curve Score",
man = "mlr3filters::mlr_filters_auc"
)
}
Expand Down
1 change: 1 addition & 0 deletions R/FilterAnova.R
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ FilterAnova = R6Class("FilterAnova",
packages = "stats",
feature_types = c("integer", "numeric"),
task_type = "classif",
label = "ANOVA F-Test",
man = "mlr3filters::mlr_filters_anova"
)
}
Expand Down
5 changes: 3 additions & 2 deletions R/FilterCMIM.R
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#' @title Minimal Conditional Mutual Information Filter
#' @title Minimal Conditional Mutual Information Maximization Filter
#'
#' @name mlr_filters_cmim
#'
#' @description Minimal conditional mutual information maximisation filter
#' @description Minimal conditional mutual information maximization filter
#' calling [praznik::CMIM()] from package \CRANpkg{praznik}.
#'
#' This filter supports partial scoring (see [Filter]).
Expand Down Expand Up @@ -41,6 +41,7 @@ FilterCMIM = R6Class("FilterCMIM",
param_set = param_set,
feature_types = c("integer", "numeric", "factor", "ordered"),
packages = "praznik",
label = "Minimal Conditional Mutual Information Maximization",
man = "mlr3filters::mlr_filters_cmim"
)
}
Expand Down
1 change: 1 addition & 0 deletions R/FilterCarScore.R
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ FilterCarScore = R6Class("FilterCarScore",
param_set = param_set,
feature_types = "numeric",
packages = "care",
label = "Correlation-Adjusted coRrelation Score",
man = "mlr3filters::mlr_filters_carscore"
)
}
Expand Down
1 change: 1 addition & 0 deletions R/FilterCarSurvScore.R
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ FilterCarSurvScore = R6Class("FilterCarSurvScore",
param_set = ps,
feature_types = c("integer", "numeric"),
task_type = "surv",
label = "Correlation-Adjusted coRrelation Survival Score",
man = "mlr3filters::mlr_filters_carsurvscore"
)
}
Expand Down
1 change: 1 addition & 0 deletions R/FilterCorrelation.R
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ FilterCorrelation = R6Class("FilterCorrelation",
param_set = param_set,
feature_types = c("integer", "numeric"),
packages = "stats",
label = "Correlation",
man = "mlr3filters::mlr_filters_correlation"
)
}
Expand Down
1 change: 1 addition & 0 deletions R/FilterDISR.R
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ FilterDISR = R6Class("FilterDISR",
param_set = param_set,
feature_types = c("integer", "numeric", "factor", "ordered"),
packages = "praznik",
label = "Double Input Symmetrical Relevance",
man = "mlr3filters::mlr_filters_disr"
)
}
Expand Down
1 change: 1 addition & 0 deletions R/FilterFindCorrelation.R
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ FilterFindCorrelation = R6Class("FilterFindCorrelation",
param_set = param_set,
feature_types = c("integer", "numeric"),
packages = "stats",
label = "Correlation-based Score",
man = "mlr3filters::mlr_filters_find_correlation"
)
}
Expand Down
1 change: 1 addition & 0 deletions R/FilterImportance.R
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ FilterImportance = R6Class("FilterImportance",
feature_types = learner$feature_types,
packages = learner$packages,
param_set = learner$param_set,
label = "Importance Score",
man = "mlr3filters::mlr_filters_importance"
)
}
Expand Down
1 change: 1 addition & 0 deletions R/FilterInformationGain.R
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ FilterInformationGain = R6Class("FilterInformationGain",
param_set = param_set,
feature_types = c("integer", "numeric", "factor", "ordered"),
packages = "FSelectorRcpp",
label = "Information Gain",
man = "mlr3filters::mlr_filters_information_gain"
)
}
Expand Down
1 change: 1 addition & 0 deletions R/FilterJMI.R
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ FilterJMI = R6Class("FilterJMI",
param_set = param_set,
packages = "praznik",
feature_types = c("integer", "numeric", "factor", "ordered"),
label = "Joint Mutual Information",
man = "mlr3filters::mlr_filters_jmi"
)
}
Expand Down
5 changes: 3 additions & 2 deletions R/FilterJMIM.R
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#' @title Minimal Joint Mutual Information Maximisation Filter
#' @title Minimal Joint Mutual Information Maximization Filter
#'
#' @name mlr_filters_jmim
#'
#' @description Minimal joint mutual information maximisation filter calling
#' @description Minimal joint mutual information maximization filter calling
#' [praznik::JMIM()] in package \CRANpkg{praznik}.
#'
#' This filter supports partial scoring (see [Filter]).
Expand Down Expand Up @@ -40,6 +40,7 @@ FilterJMIM = R6Class("FilterJMIM",
param_set = param_set,
packages = "praznik",
feature_types = c("integer", "numeric", "factor", "ordered"),
label = "Minimal Joint Mutual Information Maximization",
man = "mlr3filters::mlr_filters_jmim"
)
}
Expand Down
1 change: 1 addition & 0 deletions R/FilterKruskalTest.R
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ FilterKruskalTest = R6Class("FilterKruskalTest",
param_set = param_set,
packages = "stats",
feature_types = c("integer", "numeric"),
label = "Kruskal-Wallis Test",
man = "mlr3filters::mlr_filters_kruskal_test"
)
}
Expand Down
3 changes: 2 additions & 1 deletion R/FilterMIM.R
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#' @title Conditional Mutual Information Based Feature Selection Filter
#' @title Mutual Information Maximization Filter
#'
#' @name mlr_filters_mim
#'
Expand Down Expand Up @@ -41,6 +41,7 @@ FilterMIM = R6Class("FilterMIM",
param_set = param_set,
packages = "praznik",
feature_types = c("integer", "numeric", "factor", "ordered"),
label = "Mutual Information Maximization",
man = "mlr3filters::mlr_filters_mim"
)
}
Expand Down
3 changes: 2 additions & 1 deletion R/FilterMRMR.R
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#' @title Minimum redundancy maximal relevancy filter
#' @title Minimum Redundancy Maximal Relevancy Filter
#'
#' @name mlr_filters_mrmr
#'
Expand Down Expand Up @@ -41,6 +41,7 @@ FilterMRMR = R6Class("FilterMRMR",
param_set = param_set,
packages = "praznik",
feature_types = c("integer", "numeric", "factor", "ordered"),
label = "Minimum Redundancy Maximal Relevancy",
man = "mlr3filters::mlr_filters_mrmr"
)
}
Expand Down
5 changes: 3 additions & 2 deletions R/FilterNJMIM.R
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#' @title Minimal Normalised Joint Mutual Information Maximisation Filter
#' @title Minimal Normalised Joint Mutual Information Maximization Filter
#'
#' @name mlr_filters_njmim
#'
#' @description Minimal normalised joint mutual information maximisation filter
#' @description Minimal normalised joint mutual information maximization filter
#' calling [praznik::NJMIM()] from package \CRANpkg{praznik}.
#'
#' This filter supports partial scoring (see [Filter]).
Expand Down Expand Up @@ -40,6 +40,7 @@ FilterNJMIM = R6Class("FilterNJMIM",
param_set = param_set,
packages = "praznik",
feature_types = c("integer", "numeric", "factor", "ordered"),
label = "Minimal Normalised Joint Mutual Information Maximization",
man = "mlr3filters::mlr_filters_njmim"
)
}
Expand Down
1 change: 1 addition & 0 deletions R/FilterPerformance.R
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ FilterPerformance = R6Class("FilterPerformance",
param_set = learner$param_set,
feature_types = learner$feature_types,
packages = packages,
label = "Predictive Performance",
man = "mlr3filters::mlr_filters_performance"
)
}
Expand Down
3 changes: 2 additions & 1 deletion R/FilterPermutation.R
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#' @title Permutation Filter
#' @title Permutation Score Filter
#'
#' @name mlr_filters_permutation
#'
Expand Down Expand Up @@ -59,6 +59,7 @@ FilterPermutation = R6Class("FilterPermutation",
feature_types = learner$feature_types,
packages = packages,
param_set = param_set,
label = "Permutation Score",
man = "mlr3filters::mlr_filters_performance"
)
}
Expand Down
3 changes: 2 additions & 1 deletion R/FilterRelief.R
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#' @title Information Gain Filter
#' @title RELIEF Filter
#'
#' @name mlr_filters_relief
#'
Expand Down Expand Up @@ -33,6 +33,7 @@ FilterRelief = R6Class("FilterRelief",
param_set = param_set,
feature_types = c("integer", "numeric", "factor", "ordered"),
packages = "FSelectorRcpp",
label = "RELIEF",
man = "mlr3filters::mlr_filters_relief"
)
}
Expand Down
1 change: 1 addition & 0 deletions R/FilterSelectedFeatures.R
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ FilterSelectedFeatures = R6Class("FilterSelectedFeatures",
feature_types = learner$feature_types,
packages = learner$packages,
param_set = learner$param_set,
label = "Embedded Feature Selection",
man = "mlr3filters::mlr_filters_selected_features"
)
}
Expand Down
1 change: 1 addition & 0 deletions R/FilterVariance.R
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ FilterVariance = R6Class("FilterVariance",
param_set = param_set,
packages = "stats",
feature_types = c("integer", "numeric"),
label = "Variance",
man = "mlr3filters::mlr_filters_variance"
)
}
Expand Down
4 changes: 4 additions & 0 deletions R/helper.R
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,7 @@ call_praznik = function(self, task, fun, nfeat) {

set_names(seq(from = 1, to = 0, length.out = length(selection)), names(selection))
}

catn = function(..., file = "") {
cat(paste0(..., collapse = "\n"), "\n", sep = "", file = file)
}
18 changes: 9 additions & 9 deletions R/mlr_filters.R
Original file line number Diff line number Diff line change
Expand Up @@ -27,16 +27,16 @@ mlr_filters = DictionaryFilter = R6Class("DictionaryFilter",


#' @export
as.data.table.DictionaryFilter = function(x, ...) {
as.data.table.DictionaryFilter = function(x, ..., objects = FALSE) {
assert_flag(objects)

setkeyv(map_dtr(x$keys(), function(key) {
l = x$get(key)
list(
key = key,
task_type = list(l$task_type),
task_properties = list(l$task_properties),
param_set = list(l$param_set),
feature_types = list(l$feature_types),
packages = list(l$packages)
f = x$get(key)
insert_named(
list(key = key, label = f$label, task_type = list(f$task_type),
task_properties = list(f$task_properties), params = list(f$param_set$ids()),
feature_types = list(f$feature_types), packages = list(f$packages)),
if (objects) list(object = list(f))
)
}), "key")[]
}
2 changes: 0 additions & 2 deletions man-roxygen/field_feature_types.R

This file was deleted.

3 changes: 0 additions & 3 deletions man-roxygen/field_id.R

This file was deleted.

2 changes: 0 additions & 2 deletions man-roxygen/field_packages.R

This file was deleted.

2 changes: 0 additions & 2 deletions man-roxygen/field_param_set.R

This file was deleted.

2 changes: 0 additions & 2 deletions man-roxygen/field_task_properties.R

This file was deleted.

6 changes: 0 additions & 6 deletions man-roxygen/field_task_type.R

This file was deleted.

Loading
点击 这是indexloc提供的php浏览器服务,不要输入任何密码和下载