Skip to Content
OchreML
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 N6 Histogram Primitives: Powered directly by OchreML's N6 backend (quantize_features, batched_histogram_grad, and find_best_histogram_split).
  • CUDA & wgpu GPU Execution: Computes (sum_grad, sum_hess, count) histograms over quantized u8 feature bins on CUDA and wgpu devices, applying sibling histogram subtraction to cut split-finding work in half.
  • CPU Rayon & TPU Fallback: Runs multi-threaded N6 histogram 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

ParameterTypeDefaultDescription
lossstr"squared_error"Loss function to optimize: "squared_error" (L2) or "absolute_error" (L1).
learning_ratefloat0.1Shrinkage factor applied to each tree's leaf values.
max_iterint100Maximum number of boosting iterations (number of trees).
max_leaf_nodesint | None31Maximum number of leaves for each tree (best-first leaf-wise growth).
max_depthint | NoneNoneMaximum depth of each tree (None means unbounded depth constrained by max_leaf_nodes).
min_samples_leafint20Minimum number of training samples required per leaf.
l2_regularizationfloat0.0L2 regularization weight lambda used in leaf value and split gain computation.
max_binsint255Maximum number of histogram bins for non-missing feature values (2..=255).
random_stateint | NoneNoneRandom seed for reproducibility.
devicestr | NoneNoneExecution device ("auto", "cpu", "cuda:0", "wgpu"). Defaults to ochreml.get_default_device().

Attributes

AttributeTypeDescription
n_features_in_int | NoneNumber of features seen during fit.
n_iter_intNumber of boosting iterations actually performed.
device_str | NoneResolved hardware device string used by the underlying Rust estimator.

Methods

MethodSignatureDescription
fitfit(X, y, sample_weight=None) -> HistGradientBoostingRegressorFit the histogram gradient boosting regressor on (X, y) with optional sample weights.
predictpredict(X) -> np.ndarrayPredict continuous target values for samples in X.
scorescore(X, y) -> floatReturn the coefficient of determination R^2 on (X, y).
savesave(path: str) -> NoneSave the fitted model to a binary .dit file.
loadHistGradientBoostingRegressor.load(path: str, device: str | None = None)Load a fitted regressor from a .dit file.
toto(device: str) -> HistGradientBoostingRegressorMove 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]))

On this page