tests/testthat/test-getValidation.R

context("getValidation")
suppressPackageStartupMessages(library("randomForest"))

train <- readRDS(system.file("external/trainingPoints_rlogo.rds", package="RStoolbox"))
train$num <- rnorm(nrow(train))
class   <- superClass(, trainData = train, responseCol = "class", tuneLength = 1, trainPartition = 0.7, predict = FALSE)
reg     <- superClass(, trainData = train, responseCol = "num", tuneLength = 1, trainPartition = 0.7, predict = FALSE, mode = "regression")


test_that("getValidation returns correct objects", {
			for(f in c("testset", "cv")){
				expect_is(getValidation(class, from = f), "data.frame")
				expect_equal(nrow(getValidation(class, from = f)), 1L)
				expect_is(getValidation(class, metrics = "classwise", from = f), "data.frame")
				expect_equal(nrow(getValidation(class, metrics = "classwise", from = f)), 3)
				expect_is(getValidation(class, metrics = "confmat", from = f), "table")
				expect_is(getValidation(class, metrics = "caret", from = f), "confusionMatrix")
			}
			for(f in c("testset", "cv")){
				expect_is(getValidation(reg, from = f), "data.frame")
				expect_equal(nrow(getValidation(reg, from = f)), 1L)
			}	
		}
)

Try the RStoolbox package in your browser

Any scripts or data that you put into this service are public.

RStoolbox documentation built on May 29, 2024, 6:34 a.m.