xgboost/R-package/tests/testthat/test_poisson_regression.R
Jiaming Yuan cac2cd2e94
[R] Set number of threads in demos and tests. (#9591)
- Restrict the number of threads in IO.
- Specify the number of threads in demos and tests.
- Add helper scripts for checks.
2023-09-23 21:44:03 +08:00

16 lines
447 B
R

context('Test Poisson regression model')
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, nthread = 2
)
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)
})