1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57
|
context('misc functions')
test_that("R2 and RMSE are calculating correctly", {
pred <- runif(25)
obs <- runif(25)
expect_equal(R2(pred, obs), cor(obs, pred)^2)
expect_equal(RMSE(pred, obs), sqrt(mean((pred - obs)^2)))
})
test_that("auc calculation is > .5 when Xs provide prediction", {
skip_if_not_installed("MLmetrics")
skip_if_not_installed("earth")
skip_if_not_installed("mda")
trCntlListMulti <-
trainControl(
method = "cv",
number = 3,
verboseIter = FALSE,
classProbs = TRUE,
summaryFunction = multiClassSummary
)
set.seed(3453)
knnFit <- train(Species ~ .,
data = iris,
method = "knn",
trControl = trCntlListMulti)
expect_true(all(knnFit$resample$AUC > .5))
library(caret)
set.seed(1)
tr_dat <- twoClassSim(200)
te_dat <- tr_dat
tr_dat$Class = factor(tr_dat$Class, levels = rev(levels(te_dat$Class)))
modle <- train(
Class ~ .,
data = te_dat,
method = "fda",
tuneLength = 10,
metric = "ROC",
trControl = trainControl(classProbs = TRUE,
summaryFunction = twoClassSummary)
)
expect_true(all(modle$resample$AUC > .5))
})
|