TST: Added test for xgb.importance
This commit is contained in:
parent
78afd6c772
commit
d833038ba1
@ -1,17 +1,27 @@
|
|||||||
context('Test helper functions')
|
context('Test helper functions')
|
||||||
|
|
||||||
require(xgboost)
|
require(xgboost)
|
||||||
|
require(data.table)
|
||||||
|
require(Matrix)
|
||||||
|
require(vcd)
|
||||||
|
|
||||||
|
data(Arthritis)
|
||||||
data(agaricus.train, package='xgboost')
|
data(agaricus.train, package='xgboost')
|
||||||
data(agaricus.test, package='xgboost')
|
df <- data.table(Arthritis, keep.rownames = F)
|
||||||
train <- agaricus.train
|
df[,AgeDiscret:= as.factor(round(Age/10,0))]
|
||||||
test <- agaricus.test
|
df[,AgeCat:= as.factor(ifelse(Age > 30, "Old", "Young"))]
|
||||||
|
df[,ID:=NULL]
|
||||||
|
sparse_matrix = sparse.model.matrix(Improved~.-1, data = df)
|
||||||
|
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")
|
||||||
|
|
||||||
bst <- xgboost(data = train$data, label = train$label, max.depth = 2,
|
|
||||||
eta = 1, nthread = 2, nround = 2,objective = "binary:logistic")
|
|
||||||
|
|
||||||
test_that("dump works", {
|
test_that("xgb.dump works", {
|
||||||
capture.output(print(xgb.dump(bst)))
|
capture.output(print(xgb.dump(bst)))
|
||||||
})
|
})
|
||||||
|
|
||||||
|
test_that("xgb.importance works", {
|
||||||
|
xgb.dump(bst, 'xgb.model.dump', with.stats = T)
|
||||||
|
importance <- xgb.importance(sparse_matrix@Dimnames[[2]], 'xgb.model.dump')
|
||||||
|
})
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user