Joel Therrien
fdc708dad5
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.
27 lines
861 B
R
27 lines
861 B
R
context("Train, save, and load without error")
|
|
|
|
test_that("Can save & load regression example", {
|
|
|
|
expect_false(file.exists("trees_saving_loading")) # Folder shouldn't exist yet
|
|
|
|
x1 <- rnorm(1000)
|
|
x2 <- rnorm(1000)
|
|
y <- 1 + x1 + x2 + rnorm(1000)
|
|
|
|
data <- data.frame(x1, x2, y)
|
|
forest <- train(y ~ x1 + x2, data,
|
|
ntree=100, numberOfSplits = 5, mtry = 1, nodeSize = 5,
|
|
displayProgress=FALSE)
|
|
|
|
|
|
saveForest(forest, "trees_saving_loading")
|
|
new_forest <- loadForest("trees_saving_loading")
|
|
|
|
# try making a little prediction to verify it works
|
|
newData <- data.frame(x1=seq(from=-3, to=3, by=0.5), x2=0)
|
|
predictions <- predict(new_forest, newData)
|
|
|
|
expect_true(file.exists("trees_saving_loading")) # show Ok if we got this far
|
|
unlink("trees_saving_loading", recursive=TRUE)
|
|
|
|
})
|