Skip to content

Commit

Permalink
rebuild
Browse files Browse the repository at this point in the history
  • Loading branch information
zachmayer committed Jul 26, 2024
1 parent aa0cf3c commit b6709a2
Show file tree
Hide file tree
Showing 8 changed files with 11,960 additions and 40 deletions.
1 change: 0 additions & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ Imports:
methods,
pbapply,
ggplot2,
digest,
lattice,
gridExtra,
data.table,
Expand Down
2 changes: 1 addition & 1 deletion R/caretEnsemble.R
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ varImp.caretEnsemble <- function(object, ...) {

# Order and return
data.table::setorderv(imp, "overall", order = -1L)
data.table::setcolorder(imp, c("var", "overallq", model_names))
data.table::setcolorder(imp, c("var", "overall", model_names))
imp
}

Expand Down
1,319 changes: 1,319 additions & 0 deletions cobertura.xml

Large diffs are not rendered by default.

10,620 changes: 10,620 additions & 0 deletions coverage-report.html

Large diffs are not rendered by default.

Binary file added coverage.rds
Binary file not shown.
4 changes: 3 additions & 1 deletion man/varImp.caretEnsemble.Rd

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

4 changes: 3 additions & 1 deletion man/varImpDataTable.Rd

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

50 changes: 14 additions & 36 deletions tests/testthat/test-ensembleMethods.R
Original file line number Diff line number Diff line change
Expand Up @@ -16,24 +16,19 @@ data(Y.class)
test_that("We can get variable importance in ensembles", {
set.seed(2239L)
ens.class <- caretEnsemble(models.class, trControl = trainControl(method = "none"))
# varImp struggles with the rf in our test suite, why?
models.subset <- models.reg[2L:4L]
class(models.subset) <- "caretList"
ens.reg <- caretEnsemble(models.subset, trControl = trainControl(method = "none"))
ens.reg <- caretEnsemble(models.reg, trControl = trainControl(method = "none"))
expect_is(varImp(ens.class), "data.frame")
expect_is(varImp(ens.class, weight = TRUE), "data.frame")
expect_is(varImp(ens.class, scale = TRUE, weight = TRUE), "data.frame")
expect_is(varImp(ens.class, scale = TRUE), "data.frame")
expect_is(varImp(ens.reg), "data.frame")
expect_is(varImp(ens.reg, weight = TRUE), "data.frame")
expect_is(varImp(ens.reg, scale = TRUE, weight = TRUE), "data.frame")
expect_is(varImp(ens.reg, scale = TRUE), "data.frame")
})

test_that("varImp works for caretEnsembles", {
set.seed(2239L)
for (models in list(models.class, models.reg)) {
ens <- caretEnsemble(models, trControl = trainControl(method = "none"))
expected_names <- c("overall", names(ens$models))
expected_row_names <- c(
expected_names <- c("var", "overall", names(ens$models))
expected_var_names <- c(
"Intercept",
"Speciesversicolor",
"Speciesvirginica",
Expand All @@ -42,39 +37,22 @@ test_that("varImp works for caretEnsembles", {
"Petal.Length"
)
for (s in c(TRUE, FALSE)) {
for (w in c(TRUE, FALSE)) {
i <- varImp(ens, scale = s, weight = w)
expect_is(i, "data.frame")
expect_named(i, expected_names)
expect_equal(sort(row.names(i)), sort(expected_row_names))
}
i <- varImp(ens, scale = s)
expect_is(i, "data.frame")
expect_named(i, expected_names)
expect_equal(sort(i[["var"]]), sort(expected_var_names))
}
}
})

test_that("We get the right dimensions back", {
ncol1 <- 5L
ncol2 <- 4L
nrow1 <- 6L
nrow2 <- 6L
set.seed(2239L)
ens.class <- caretEnsemble(models.class, trControl = trainControl(method = "none"))
# varImp struggles with the rf in our test suite, why?
models.subset <- models.reg[2L:4L]
class(models.subset) <- "caretList"
ens.reg <- caretEnsemble(models.subset, trControl = trainControl(method = "none"))
expect_equal(ncol(varImp(ens.class)), ncol1)
expect_equal(ncol(varImp(ens.class, weight = FALSE)), ncol1)
expect_equal(ncol(varImp(ens.class, weight = TRUE)), ncol1)
expect_equal(ncol(varImp(ens.reg)), ncol2)
expect_equal(ncol(varImp(ens.reg, weight = FALSE)), ncol2)
expect_equal(ncol(varImp(ens.reg, weight = TRUE)), ncol2)
expect_equal(nrow(varImp(ens.class)), nrow1)
expect_equal(nrow(varImp(ens.class, weight = FALSE)), nrow1)
expect_equal(nrow(varImp(ens.class, weight = TRUE)), nrow1)
expect_equal(nrow(varImp(ens.reg)), nrow2)
expect_equal(nrow(varImp(ens.reg, weight = FALSE)), nrow2)
expect_equal(nrow(varImp(ens.reg, weight = TRUE)), nrow2)
ens.reg <- caretEnsemble(models.reg, trControl = trainControl(method = "none"))
expect_equal(ncol(varImp(ens.class)), 6L)
expect_equal(ncol(varImp(ens.reg)), 6L)
expect_equal(nrow(varImp(ens.class)), 6L)
expect_equal(nrow(varImp(ens.reg)), 6L)
})

context("Do metric extraction functions work as expected")
Expand Down

0 comments on commit b6709a2

Please sign in to comment.