Merge pull request #471 from terrytangyuan/master
TST: Added R unit test for glm
This commit is contained in:
commit
6109a70a16
19
R-package/tests/testthat/test_glm.R
Normal file
19
R-package/tests/testthat/test_glm.R
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
context('Test generalized linear models')
|
||||||
|
|
||||||
|
require(xgboost)
|
||||||
|
|
||||||
|
test_that("glm works", {
|
||||||
|
data(agaricus.train, package='xgboost')
|
||||||
|
data(agaricus.test, package='xgboost')
|
||||||
|
dtrain <- xgb.DMatrix(agaricus.train$data, label = agaricus.train$label)
|
||||||
|
dtest <- xgb.DMatrix(agaricus.test$data, label = agaricus.test$label)
|
||||||
|
expect_equal(class(dtrain), "xgb.DMatrix")
|
||||||
|
expect_equal(class(dtest), "xgb.DMatrix")
|
||||||
|
param <- list(objective = "binary:logistic", booster = "gblinear",
|
||||||
|
nthread = 2, alpha = 0.0001, lambda = 1)
|
||||||
|
watchlist <- list(eval = dtest, train = dtrain)
|
||||||
|
num_round <- 2
|
||||||
|
bst <- xgb.train(param, dtrain, num_round, watchlist)
|
||||||
|
ypred <- predict(bst, dtest)
|
||||||
|
expect_equal(length(getinfo(dtest, 'label')), 1611)
|
||||||
|
})
|
||||||
Loading…
x
Reference in New Issue
Block a user