LightGBM (Light Gradient Boosting Machine) implementation.
Classes
LightGBM classifier for distributed, high-performance gradient boosting.
__init__( self, n_estimators: int = 100, max_depth: int = ..., learning_rate: float = 0.1, num_leaves: int = 31, subsample: float = 1.0, colsample_bytree: float = 1.0, reg_alpha: float = 0.0, reg_lambda: float = 0.0, min_child_samples: int = 20, min_split_gain: float = 0.0, verbose: int = ..., random_state: Optional[int] = None, )
Overview
The algorithm builds an ensemble of decision trees using leaf-wise growth:
- Initialize the model with a constant prediction (e.g., log-odds for
- For each boosting iteration, compute the negative gradient of the
- Build histograms of feature values using gradient-based one-side
- Grow the tree leaf-wise by splitting the leaf with the highest
num_leaves
- Add the new tree to the ensemble, scaled by the learning rate
- Repeat until the specified number of boosting rounds is reached
Theory
At each boosting round t, LightGBM minimizes:
where the regularization term is:
GOSS keeps all instances with large gradients and randomly samples from instances with small gradients, multiplying them by \frac{1-a}{b} to compensate:
where A is the set of top-a instances and B is sampled from the remaining instances with ratio b.
Parameters
n_estimators
max_depth
-1 means no limit.
learning_rate
num_leaves
subsample
colsample_bytree
reg_alpha
reg_lambda
min_child_samples
min_split_gain
verbose
-1: Quiet, 0: Warnings, 1: Info.
random_state
Attributes
model_
classes_
fit().
n_classes_
fit().
Notes
Complexity:
- Training: O(T \cdot n \cdot d \cdot L) where T = n_estimators,
- Prediction: O(T \cdot L) per sample
- Large-scale classification tasks where training speed is critical
- High-dimensional datasets where exclusive feature bundling reduces cost
- When memory efficiency is important (histogram-based approach)
- Distributed training scenarios across multiple machines
References
See Also
Train a LightGBM classifier on a binary classification task:
>>> from tuiml.algorithms.gradient_boosting import LightGBMClassifier
>>> import numpy as np
>>>
>>> X_train = np.array([[1, 2], [3, 4], [5, 6], [7, 8]])
>>> y_train = np.array([0, 0, 1, 1])
>>> clf = LightGBMClassifier(n_estimators=100, num_leaves=31)
>>> clf.fit(X_train, y_train)
>>> y_pred = clf.predict(X_train)
Methods
__repr__
(self) -> str
LightGBM regressor for distributed, high-performance gradient boosting on continuous targets.
__init__( self, n_estimators: int = 100, max_depth: int = ..., learning_rate: float = 0.1, num_leaves: int = 31, subsample: float = 1.0, colsample_bytree: float = 1.0, reg_alpha: float = 0.0, reg_lambda: float = 0.0, min_child_samples: int = 20, min_split_gain: float = 0.0, verbose: int = ..., random_state: Optional[int] = None, )
Overview
The regression variant follows the same leaf-wise boosting procedure:
- Initialize predictions with a constant value (e.g., mean of targets)
- For each boosting iteration, compute the negative gradient of the
- Build feature histograms using GOSS (gradient-based one-side
- Grow the tree leaf-wise by splitting the leaf with the highest
num_leaves
- Add the new tree to the ensemble, scaled by the learning rate
- Repeat until the specified number of boosting rounds is reached
Theory
For the default squared-error objective, the loss for sample i is:
The regularized objective at round t is:
The optimal leaf weight for leaf j is:
where g_i is the gradient, \lambda is the L2 regularization term (reg_lambda), and \alpha is the L1 term (reg_alpha).
Parameters
n_estimators
max_depth
-1 means no limit.
learning_rate
num_leaves
subsample
colsample_bytree
reg_alpha
reg_lambda
min_child_samples
min_split_gain
verbose
-1: Quiet, 0: Warnings, 1: Info.
random_state
Attributes
model_
Notes
Complexity:
- Training: O(T \cdot n \cdot d \cdot L) where T = n_estimators,
- Prediction: O(T \cdot L) per sample
- Large-scale regression tasks where training speed is critical
- High-dimensional datasets where exclusive feature bundling reduces cost
- When memory efficiency is important (histogram-based approach)
- Distributed training scenarios across multiple machines
References
See Also
Train a LightGBM regressor on a simple regression task:
>>> from tuiml.algorithms.gradient_boosting import LightGBMRegressor
>>> import numpy as np
>>>
>>> X_train = np.array([[1, 2], [3, 4], [5, 6], [7, 8]])
>>> y_train = np.array([1.5, 3.5, 5.5, 7.5])
>>> reg = LightGBMRegressor(n_estimators=100, learning_rate=0.05)
>>> reg.fit(X_train, y_train)
>>> y_pred = reg.predict(X_train)
Methods
__repr__
(self) -> str