Skip to content

Commit a3e43f9

Browse files
committed
remove Metrics
1 parent 905df71 commit a3e43f9

File tree

5 files changed

+31
-14
lines changed

5 files changed

+31
-14
lines changed

DESCRIPTION

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ Suggests:
3939
care,
4040
FSelectorRcpp,
4141
lgr,
42+
mlr3measures,
4243
mlr3learners,
4344
praznik,
4445
rpart,

R/FilterAUC.R

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,11 @@
1212
#' flt("auc")
1313
#' ```
1414
#'
15-
#' @description Area under the (ROC) Curve filter calling [Metrics::auc()] from
16-
#' package \CRANpkg{Metrics}. Returns the absolute value of the difference
17-
#' between the AUC and 0.5.
15+
#' @description
16+
#' Area under the (ROC) Curve filter, analogously to [mlr3measures::auc()] from \CRANpkg{mlr3meaures}.
17+
#' Missing values of the features are removed before calculating the AUC.
18+
#' If the AUC is undefined for the input, it is set to 0.5 (random classifier).
19+
#' The absolute value of the difference between the AUC and 0.5 is used as final filter value.
1820
#'
1921
#' @family Filter
2022
#' @template seealso_filter
@@ -29,21 +31,34 @@ FilterAUC = R6Class("FilterAUC", inherit = Filter,
2931
initialize = function() {
3032
super$initialize(
3133
id = "auc",
32-
packages = "Metrics",
34+
packages = "mlr3measures",
3335
feature_types = c("integer", "numeric"),
3436
task_type = "classif",
3537
task_properties = "twoclass"
3638
)
3739
},
3840

3941
calculate_internal = function(task, nfeat) {
40-
x = task$truth() == task$positive
41-
y = task$data(cols = task$feature_names)
42-
score = map_dbl(y, function(y) Metrics::auc(x, y))
42+
y = task$truth() == task$positive
43+
x = task$data(cols = task$feature_names)
44+
score = map_dbl(x, function(x) {
45+
keep = !is.na(x)
46+
auc(y[keep], x[keep])
47+
})
4348
abs(0.5 - score)
4449
}
4550
)
4651
)
4752

4853
#' @include mlr_filters.R
4954
mlr_filters$add("auc", FilterAUC)
55+
56+
57+
auc = function (truth, prob) {
58+
n_pos = sum(truth)
59+
n_neg = length(truth) - n_pos
60+
if (n_pos == 0L || n_neg == 0L)
61+
return(0.5)
62+
r = rank(prob, ties.method = "average")
63+
(sum(r[truth]) - n_pos * (n_pos + 1L)/2L)/(n_pos * n_neg)
64+
}

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ as.data.table(filter$calculate(task))
5858
| Name | Task Type | Feature Types | Package |
5959
| :---------------- | :------------- | :---------------------------------------------------- | :---------------------------------------------------------------- |
6060
| anova | Classif | Integer, Numeric | stats |
61-
| auc | Classif | Integer, Numeric | [Metrics](https://cran.r-project.org/package=Metrics) |
61+
| auc | Classif | Integer, Numeric | [mlr3measures](https://cran.r-project.org/package=mlr3measures) |
6262
| carscore | Regr | Numeric | [care](https://cran.r-project.org/package=care) |
6363
| cmim | Classif & Regr | Integer, Numeric, Factor, Ordered | [praznik](https://cran.r-project.org/package=praznik) |
6464
| correlation | Regr | Integer, Numeric | stats |
@@ -79,8 +79,8 @@ as.data.table(filter$calculate(task))
7979
The following learners allow the extraction of variable importance and
8080
therefore are supported by `FilterImportance`:
8181

82-
## [1] "classif.featureless" "classif.ranger" "classif.rpart"
83-
## [4] "classif.xgboost" "regr.featureless" "regr.ranger"
82+
## [1] "classif.featureless" "classif.ranger" "classif.rpart"
83+
## [4] "classif.xgboost" "regr.featureless" "regr.ranger"
8484
## [7] "regr.rpart" "regr.xgboost"
8585

8686
If your learner is not listed here but capable of extracting variable

man/FilterAUC.Rd

Lines changed: 4 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/flt.Rd

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)