File: test_sparse_Matrix.R

package info (click to toggle)
r-cran-caret 7.0-1%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: sid, trixie
  • size: 4,036 kB
  • sloc: ansic: 210; sh: 10; makefile: 2
file content (19 lines) | stat: -rw-r--r-- 746 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
context("Testing sparse Matrix")

test_that("caret can return sparse Matrix object", {
  skip_on_cran()
  skip_if_not_installed('glmnet')
  skip_if_not_installed('Matrix')

  x <- Matrix::Matrix(as.matrix(mtcars)[, -1], sparse=TRUE)
  y <- mtcars$mpg
  expect_warning(train(x, y, method="glmnet"), NA)
  expect_warning(train(as.matrix(x), y, method="glmnet"), NA)

  cls_y <- factor(rep_len(letters[1:2], nrow(mtcars)))
  ctrl <- trainControl(method = "cv",
                       classProbs = TRUE,
                       summaryFunction = twoClassSummary)
  expect_error(train(x, cls_y, method="glmnet", metric = "ROC", trControl = ctrl), NA)
  expect_error(train(as.matrix(x), cls_y, method="glmnet", metric = "ROC", trControl = ctrl), NA)
})