[R] Add class names to coefficients (#10745)

This commit is contained in:
david-cortes
2024-08-24 22:41:58 +02:00
committed by GitHub
parent fd0138c91c
commit 479ae8081b
2 changed files with 25 additions and 4 deletions

View File

@@ -750,6 +750,19 @@ test_that("Coefficients from gblinear have the expected shape and names", {
pred_auto <- predict(model, x, outputmargin = TRUE)
pred_manual <- unname(mm %*% coefs)
expect_equal(pred_manual, pred_auto, tolerance = 1e-7)
# xgboost() with additional metadata
model <- xgboost(
iris[, -5],
iris$Species,
booster = "gblinear",
objective = "multi:softprob",
nrounds = 3,
nthread = 1
)
coefs <- coef(model)
expect_equal(row.names(coefs), c("(Intercept)", colnames(x)))
expect_equal(colnames(coefs), levels(iris$Species))
})
test_that("Deep copies work as expected", {