tests/testthat/test_lgb.importance.R

context("lgb.importance")

test_that("lgb.importance() should reject bad inputs", {
    bad_inputs <- list(
        .Machine$integer.max
        , Inf
        , -Inf
        , NA
        , NA_real_
        , -10L:10L
        , list(c("a", "b", "c"))
        , data.frame(
            x = rnorm(20L)
            , y = sample(
                x = c(1L, 2L)
                , size = 20L
                , replace = TRUE
            )
        )
        , data.table::data.table(
            x = rnorm(20L)
            , y = sample(
                x = c(1L, 2L)
                , size = 20L
                , replace = TRUE
            )
        )
        , lgb.Dataset(
            data = matrix(rnorm(100L), ncol = 2L)
            , label = matrix(sample(c(0L, 1L), 50L, replace = TRUE))
        )
        , "lightgbm.model"
    )
    for (input in bad_inputs) {
        expect_error({
            lgb.importance(input)
        }, regexp = "'model' has to be an object of class lgb\\.Booster")
    }
})

Try the lightgbm package in your browser

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

lightgbm documentation built on Jan. 17, 2023, 1:13 a.m.