Minor addition to R unit tests

This commit is contained in:
terrytangyuan
2015-10-30 19:48:00 -05:00
parent 9cdcc8303b
commit e23f4ec3db
3 changed files with 12 additions and 6 deletions

View File

@@ -5,6 +5,7 @@ require(data.table)
require(Matrix)
require(vcd)
set.seed(1994)
data(Arthritis)
data(agaricus.train, package='xgboost')
df <- data.table(Arthritis, keep.rownames = F)
@@ -16,15 +17,16 @@ output_vector <- df[,Y := 0][Improved == "Marked",Y := 1][,Y]
bst <- xgboost(data = sparse_matrix, label = output_vector, max.depth = 9,
eta = 1, nthread = 2, nround = 10,objective = "binary:logistic")
test_that("xgb.dump works", {
capture.output(print(xgb.dump(bst)))
dump <- xgb.dump(bst)
expect_equal(length(dump, 172))
})
test_that("xgb.importance works", {
xgb.dump(bst, 'xgb.model.dump', with.stats = T)
expect_true(xgb.dump(bst, 'xgb.model.dump', with.stats = T))
importance <- xgb.importance(sparse_matrix@Dimnames[[2]], 'xgb.model.dump')
expect_equal(dim(importance), c(7, 4))
expect_equal(colnames(importance), c("Feature", "Gain", "Cover", "Frequence"))
})
test_that("xgb.plot.tree works", {