largeRCRF/tests/testthat/test_adding_new_trees.R
Joel Therrien fdc708dad5 New features -
Add support for making predictions without specifying training data
Add support for adding trees to an existing forest
Add support for toggling displayProgress

Also reduced the size of the package by removing some unused dependency
classes.
2019-06-19 13:15:43 -07:00

71 lines
No EOL
2.4 KiB
R

context("Add trees on existing forest")
test_that("Can add trees on existing forest", {
trainingData <- data.frame(x=rnorm(100))
trainingData$T <- rexp(100) + abs(trainingData$x)
trainingData$delta <- sample(0:2, size = 100, replace=TRUE)
forest <- train(CR_Response(delta, T) ~ x, trainingData, ntree=50, numberOfSplits=0, mtry=1, nodeSize=5, cores=2, displayProgress=FALSE)
predictions <- predict(forest)
forest.more <- addTrees(forest, 50, cores=2, displayProgress=FALSE) # test multi-core
predictions <- predict(forest)
forest.more <- addTrees(forest.more, 50, cores=1, displayProgress=FALSE) # test single-core
expect_true(T) # show Ok if we got this far
})
test_that("Test adding trees on saved forest - using delete", {
expect_false(file.exists("trees")) # Folder shouldn't exist yet
trainingData <- data.frame(x=rnorm(100))
trainingData$T <- rexp(100) + abs(trainingData$x)
trainingData$delta <- sample(0:2, size = 100, replace=TRUE)
forest <- train(CR_Response(delta, T) ~ x, trainingData, ntree=50, numberOfSplits=0,
mtry=1, nodeSize=5, cores=2,
savePath="trees", displayProgress=FALSE
)
forest.more <- addTrees(forest, 50, cores=2, savePath = "trees", savePath.overwrite="delete", displayProgress=FALSE)
predictions <- predict(forest)
unlink("trees", recursive=TRUE)
expect_true(T) # show Ok if we got this far
})
test_that("Test adding trees on saved forest - using merge", {
expect_false(file.exists("trees")) # Folder shouldn't exist yet
trainingData <- data.frame(x=rnorm(100))
trainingData$T <- rexp(100) + abs(trainingData$x)
trainingData$delta <- sample(0:2, size = 100, replace=TRUE)
forest <- train(CR_Response(delta, T) ~ x, trainingData, ntree=50, numberOfSplits=0,
mtry=1, nodeSize=5, cores=2,
savePath="trees", displayProgress=FALSE
)
expect_warning(
addTrees(forest, 50,
cores=2,
savePath = "trees",
savePath.overwrite="merge",
displayProgress=FALSE),
"Assuming that the previous forest at savePath is the provided forest argument; if not true then your results will be suspect" )
unlink("trees", recursive=TRUE)
expect_true(T) # show Ok if we got this far
})