tests/testthat/test_poisson_regression.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)
})

Try the xgboost package in your browser

Any scripts or data that you put into this service are public.

xgboost documentation built on April 16, 2022, 5:05 p.m.