library(fastgbm)
x <- as.matrix(mtcars[, c("cyl", "disp", "hp", "wt")])
y <- mtcars$mpg
fit <- fastgbm(
x, y = y, objective = "regression",
ntrees = 100L, learning_rate = 0.1, max_depth = 3L,
seed = 1L, verbose = FALSE
)
fit
#> fastgbm model
#> objective: regression
#> trees: 100
#> learning rate: 0.1
#> max depth: 3objective can be omitted for a numeric response:
fastgbm() defaults to "regression" for any
y that is not a 0/1 vector, a two-level factor, or a
survival::Surv object.
pred <- predict(fit, x, type = "response")
head(pred)
#> [1] 20.84815 21.03444 22.50698 20.36689 17.72464 18.67521
metrics(fit, y = y)
#> $objective
#> [1] "regression"
#>
#> $metric
#> [1] "rmse"
#>
#> $value
#> [1] 0.7226311
importance(fit)
#> feature gain
#> 4 wt 1097.6196
#> 2 disp 750.0978
#> 1 cyl 337.2986
#> 3 hp 319.9553As with the other objectives, supplying
validation/early_stopping is recommended
whenever held-out performance matters – training every
ntrees round without it tends to overfit small-to-medium
datasets.