tests/testthat/test_varImp.R

context('varImp')

test_that("high level tests", {

  data(iris)
  TrainData <- iris[,1:4]
  TrainClasses <- iris[,5]

  expect_silent(
    knnFit1 <- train(TrainData, TrainClasses,
                   method = "knn",
                   preProcess = c("center", "scale"),
                   tuneLength = 10,
                   trControl = trainControl(method = "cv"))
  )

  expect_silent(vv <- varImp(knnFit1))

  expect_true(ncol(vv$importance) == length(levels(TrainClasses)))
  expect_true(nrow(vv$importance) == ncol(TrainData))

})

Try the caret package in your browser

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

caret documentation built on Aug. 9, 2022, 5:11 p.m.