Trees, Ensembles & Boosting
HistGradientBoostingClassifier
LightGBM-style histogram-based gradient boosted classifier accelerated by OchreML's N6 GPU/CPU histogram primitives.
HistGradientBoostingClassifier is a fast, LightGBM-inspired histogram-based gradient boosting classifier that quantizes continuous features into at most max_bins (2..=255) integer bins and grows leaf-wise trees using second-order gradient/hessian histograms with L2 regularization. (*≧ω≦*)
Backend & Hardware Acceleration
- Native
N6Histogram Primitives: Directly powered by OchreML'sN6backend primitives (quantize_features,batched_histogram_grad, andfind_best_histogram_split). - CUDA &
wgpuAcceleration: Accumulates(sum_grad, sum_hess, count)histograms over quantizedu8feature bins on CUDA andwgpuGPUs, using sibling histogram subtraction to halve histogram work at each split. - CPU Rayon & TPU Fallback: Runs multi-threaded
N6histogram kernels via Rust Rayon on CPU, and automatically routes to CPU Rayon on TPU targets where branch-heavy tree splitting is ill-suited for XLA MXUs.
Import & Signature
from ochreml.ensemble import HistGradientBoostingClassifier
# or: from ochreml import HistGradientBoostingClassifier
HistGradientBoostingClassifier(
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 |
|---|---|---|---|
learning_rate | float | 0.1 | Shrinkage factor applied to each tree's leaf values. |
max_iter | int | 100 | Maximum number of boosting iterations (trees per class / binary stage). |
max_leaf_nodes | int | None | 31 | Maximum number of leaf nodes per tree (best-first leaf-wise growth). |
max_depth | int | None | None | Maximum depth of each tree (None means no explicit depth limit beyond max_leaf_nodes). |
min_samples_leaf | int | 20 | Minimum number of training samples required in each 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 |
|---|---|---|
classes_ | np.ndarray | 1D float64 array of unique class labels discovered during fit. |
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) -> HistGradientBoostingClassifier | Fit the histogram gradient boosting classifier on (X, y) with optional sample weights. |
predict | predict(X) -> np.ndarray | Predict class labels for samples in X. |
predict_proba | predict_proba(X) -> np.ndarray | Predict class probabilities of shape (n_samples, n_classes). |
decision_function | decision_function(X) -> np.ndarray | Return raw decision scores before sigmoid/softmax: shape (n_samples,) for binary or (n_samples, n_classes) for multiclass. |
score | score(X, y) -> float | Return mean classification accuracy on (X, y). |
save | save(path: str) -> None | Save the fitted model to a binary .dit file. |
load | HistGradientBoostingClassifier.load(path: str, device: str | None = None) | Load a fitted classifier from a .dit file. |
to | to(device: str) -> HistGradientBoostingClassifier | Move the estimator to another execution device. |
Example
import numpy as np
from ochreml.ensemble import HistGradientBoostingClassifier
rng = np.random.default_rng(7)
X0 = rng.normal(loc=-1.0, scale=0.8, size=(150, 4))
X1 = rng.normal(loc=1.0, scale=0.8, size=(150, 4))
X = np.vstack([X0, X1])
y = np.array([0.0] * 150 + [1.0] * 150)
clf = HistGradientBoostingClassifier(
max_iter=60,
learning_rate=0.1,
max_leaf_nodes=15,
min_samples_leaf=10,
l2_regularization=1.0,
max_bins=128,
random_state=7,
device="auto",
)
clf.fit(X, y)
print("Iterations:", clf.n_iter_)
print("Accuracy:", clf.score(X, y))
print("Probabilities (first 3):\n", clf.predict_proba(X[:3]))