wrap_lightgbm: S3 wrapper for lightgbm

View source: R/wrap_lightgbm.R

wrap_lightgbmR Documentation

S3 wrapper for lightgbm

Description

Fits a 'lightgbm' model with a consistent interface. Supports binary classification, multiclass classification, and regression.

Usage

wrap_lightgbm(x, y, ...)

## S3 method for class 'wrap_lightgbm'
predict(object, newx, type = c("class", "prob"), ...)

## S3 method for class 'wrap_lightgbm'
print(x, ...)

Arguments

x

A matrix or data.frame of features.

y

A factor or character vector for classification, numeric for regression.

...

Additional arguments passed to [lightgbm::lgb.train()]. Pass 'params = list(objective = "binary")' for binary classification, 'params = list(objective = "multiclass", num_class = k)' for multiclass, or 'params = list(objective = "regression")' for regression.

object

A fitted 'wrap_lightgbm' object.

newx

A matrix or data.frame of new observations.

type

'"class"' (default) for class labels, '"prob"' for a probability matrix. Ignored for regression.

Value

An object of class 'wrap_lightgbm' with fields:

fit

The fitted lgb.Booster model.

levels

Class levels (NULL for regression).

task

"classification" or "regression".

objective

The lightgbm objective string, stored at fit time.

Examples


library(mlS3)

X <- iris[, 1:4]
y <- iris$Species
mod <- wrap_lightgbm(X, y,
  params = list(objective = "multiclass", num_class = 3, verbose = -1),
  nrounds = 50)
predict(mod, newx = X, type = "class")
predict(mod, newx = X, type = "prob")


mlS3 documentation built on April 29, 2026, 1:08 a.m.