Skip to content

Commit

Permalink
Merge branch 'main' of github.com:ampel-leipzig/rusranger
Browse files Browse the repository at this point in the history
  • Loading branch information
sgibb committed Mar 25, 2022
2 parents 824fb78 + 1778d3b commit 6e1ee26
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 1 deletion.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Package: rusranger
Title:
Modified ranger implementation to support random-under-sampling
Version: 0.0.1
Version: 0.0.2
Date: 2022-03-24
Description:
The random forest implementation of the ranger package is modified to
Expand Down
4 changes: 4 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# rusranger 0.0

## Changes in 0.0.2

- Fix `.caseweights` for 0/1 binary class coding (instead of 1/2).

## Changes in 0.0.1

- Initial version.
1 change: 1 addition & 0 deletions R/utils-rusranger.R
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
#' @return `double(length(y))` with case weights
#' @noRd
.caseweights <- function(y, replace = FALSE) {
y <- as.factor(y)
if (isTRUE(replace))
## these case weights work just for replace = TRUE (=> bootstrap)
c(1 / table(y))[y]
Expand Down
6 changes: 6 additions & 0 deletions tests/testthat/test_utils-rusranger.R
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,12 @@ test_that(".caseweights", {
.caseweights(cl, replace = TRUE),
setNames(rep(c(0.5, 0.25), c(2, 4)), cl)
)
## fix error if classes are numerics other as 1:2
cl <- rep(0:1, c(2, 4))
expect_equal(
unname(.caseweights(cl, replace = FALSE)),
unname(.caseweights(cl + 1, replace = FALSE)),
)
})

test_that(".samplefraction", {
Expand Down

0 comments on commit 6e1ee26

Please sign in to comment.