xgboost/R-package/tests/testthat/test_poisson_regression.R
Andrew Ziem 3e7e426b36
Fix spelling in documents (#6948)
* Update roxygen2 doc.

Co-authored-by: fis <jm.yuan@outlook.com>
2021-05-11 20:44:36 +08:00

15 lines
455 B
R

context('Test Poisson regression model')
require(xgboost)
set.seed(1994)
test_that("Poisson regression works", {
data(mtcars)
bst <- xgboost(data = as.matrix(mtcars[, -11]), label = mtcars[, 11],
objective = 'count:poisson', nrounds = 10, verbose = 0)
expect_equal(class(bst), "xgb.Booster")
pred <- predict(bst, as.matrix(mtcars[, -11]))
expect_equal(length(pred), 32)
expect_lt(sqrt(mean((pred - mtcars[, 11])^2)), 1.2)
})