Trees, Ensembles & Boosting
HistGradientBoostingRegressor
LightGBM-style histogram-based gradient boosted regressor accelerated by OchreML's N6 GPU/CPU histogram primitives.
HistGradientBoostingRegressor bins continuous features into at most max_bins (2..=255) discrete levels and grows leaf-wise regression trees using second-order gradient/hessian histograms with optional L2 regularization. (^▽^)
Backend & Hardware Acceleration
- Native
N6Histogram Primitives: Powered directly by OchreML'sN6backend (quantize_features,batched_histogram_grad, andfind_best_histogram_split). - CUDA &
wgpuGPU Execution: Computes(sum_grad, sum_hess, count)histograms over quantizedu8feature bins on CUDA andwgpudevices, applying sibling histogram subtraction to cut split-finding work in half. - CPU Rayon & TPU Fallback: Runs multi-threaded
N6histogram kernels via Rust Rayon on CPU and automatically routes to CPU Rayon on TPU targets.
Import & Signature
from ochreml.ensemble import HistGradientBoostingRegressor
# or: from ochreml import HistGradientBoostingRegressor
HistGradientBoostingRegressor(
loss: str = "squared_error",
learning_rate: float = 0.1,
max_iter: int = 100,
max_leaf_nodes: Optional[int] = 31,
max_depth: Optional[int] = None,
min_samples_leaf: int = 20,
l2_regularization: float = 0.0,
max_bins: int = 255,
random_state: Optional[int] = None,
device: Optional[str] = None,
)Parameters
| Parameter | Type | Default | Description |
|---|---|---|---|
loss | str | "squared_error" | Loss function to optimize: "squared_error" (L2) or "absolute_error" (L1). |
learning_rate | float | 0.1 | Shrinkage factor applied to each tree's leaf values. |
max_iter | int | 100 | Maximum number of boosting iterations (number of trees). |
max_leaf_nodes | int | None | 31 | Maximum number of leaves for each tree (best-first leaf-wise growth). |
max_depth | int | None | None | Maximum depth of each tree (None means unbounded depth constrained by max_leaf_nodes). |
min_samples_leaf | int | 20 | Minimum number of training samples required per leaf. |
l2_regularization | float | 0.0 | L2 regularization weight lambda used in leaf value and split gain computation. |
max_bins | int | 255 | Maximum number of histogram bins for non-missing feature values (2..=255). |
random_state | int | None | None | Random seed for reproducibility. |
device | str | None | None | Execution device ("auto", "cpu", "cuda:0", "wgpu"). Defaults to ochreml.get_default_device(). |
Attributes
| Attribute | Type | Description |
|---|---|---|
n_features_in_ | int | None | Number of features seen during fit. |
n_iter_ | int | Number of boosting iterations actually performed. |
device_ | str | None | Resolved hardware device string used by the underlying Rust estimator. |
Methods
| Method | Signature | Description |
|---|---|---|
fit | fit(X, y, sample_weight=None) -> HistGradientBoostingRegressor | Fit the histogram gradient boosting regressor on (X, y) with optional sample weights. |
predict | predict(X) -> np.ndarray | Predict continuous target values for samples in X. |
score | score(X, y) -> float | Return the coefficient of determination R^2 on (X, y). |
save | save(path: str) -> None | Save the fitted model to a binary .dit file. |
load | HistGradientBoostingRegressor.load(path: str, device: str | None = None) | Load a fitted regressor from a .dit file. |
to | to(device: str) -> HistGradientBoostingRegressor | Move the estimator to another execution device. |
Example
import numpy as np
from ochreml.ensemble import HistGradientBoostingRegressor
rng = np.random.default_rng(21)
X = rng.uniform(-3.0, 3.0, size=(300, 3))
y = np.sin(X[:, 0]) + 0.4 * X[:, 1] ** 2 - 0.2 * X[:, 2]
reg = HistGradientBoostingRegressor(
loss="squared_error",
max_iter=80,
learning_rate=0.1,
max_leaf_nodes=15,
min_samples_leaf=10,
l2_regularization=0.1,
max_bins=128,
random_state=21,
device="auto",
)
reg.fit(X, y)
print("Iterations:", reg.n_iter_)
print("R^2 score:", reg.score(X, y))
print("Sample predictions:", reg.predict(X[:4]))