Skip to Content
OchreML
Trees, Ensembles & Boosting

GradientBoostingRegressor

Stagewise gradient boosted regression trees supporting squared_error, absolute_error, and Huber losses with staged_predict.

GradientBoostingRegressor builds an additive sequence of shallow regression trees, each trained on the negative gradient (pseudo-residuals) of a differentiable regression loss (squared_error, absolute_error, or huber). (^▽^)

Backend & Hardware Acceleration

  • CPU Rayon Parallelism: Boosting iterations execute sequentially while tree split finding, residual updates, and predictions are parallelized across CPU threads with Rust Rayon.
  • Accelerator Notes: Uses OchreML's N2 / N6 primitives where applicable and runs branch-heavy tree stages on CPU Rayon (including automatic CPU Rayon fallback on TPU). For large tabular datasets that benefit from full u8-binned GPU histogram acceleration, see HistGradientBoostingRegressor.

Import & Signature

from ochreml.ensemble import GradientBoostingRegressor
# or: from ochreml import GradientBoostingRegressor

GradientBoostingRegressor(
    loss: str = "squared_error",
    learning_rate: float = 0.1,
    n_estimators: int = 100,
    subsample: float = 1.0,
    min_samples_split: int = 2,
    min_samples_leaf: int = 1,
    max_depth: int = 3,
    alpha: float = 0.9,
    random_state: Optional[int] = None,
    device: Optional[str] = None,
)

Parameters

ParameterTypeDefaultDescription
lossstr"squared_error"Loss function to optimize: "squared_error" (L2), "absolute_error" (L1), or "huber" (hybrid L2/L1).
learning_ratefloat0.1Shrinkage factor applied to each tree's contribution.
n_estimatorsint100Number of boosting stages to perform.
subsamplefloat1.0Fraction of samples used to fit each base learner (< 1.0 enables Stochastic Gradient Boosting).
min_samples_splitint2Minimum number of samples required to split an internal node.
min_samples_leafint1Minimum number of samples required at a leaf node.
max_depthint3Maximum depth of each individual regression tree.
alphafloat0.9Quantile threshold used by the "huber" loss function.
random_stateint | NoneNoneRandom seed controlling subsampling and tree randomness at each stage.
devicestr | NoneNoneExecution device ("auto", "cpu", "cuda:0", "wgpu", "tpu"). Defaults to ochreml.get_default_device().

Attributes

AttributeTypeDescription
feature_importances_np.ndarray | NoneNormalized impurity-based feature importances of shape (n_features,).
n_features_in_int | NoneNumber of features seen during fit.
device_str | NoneResolved hardware device string used by the underlying Rust estimator.

Methods

MethodSignatureDescription
fitfit(X, y, sample_weight=None) -> GradientBoostingRegressorFit the gradient boosting regressor on (X, y) with optional sample weights.
predictpredict(X) -> np.ndarrayPredict continuous target values for samples in X.
staged_predictstaged_predict(X) -> Iterator[np.ndarray]Yield predicted target arrays after each boosting stage 1..n_estimators for monitoring convergence.
scorescore(X, y) -> floatReturn the coefficient of determination R^2 on (X, y).
savesave(path: str) -> NoneSave the fitted boosting model to a binary .dit file.
loadGradientBoostingRegressor.load(path: str, device: str | None = None)Load a fitted regressor from a .dit file.
toto(device: str) -> GradientBoostingRegressorMove the estimator execution target to device.

Example

import numpy as np
from ochreml.ensemble import GradientBoostingRegressor

rng = np.random.default_rng(10)
X = rng.uniform(-3.0, 3.0, size=(120, 2))
y = np.cos(X[:, 0]) + 0.5 * X[:, 1] ** 2

reg = GradientBoostingRegressor(
    loss="huber",
    alpha=0.9,
    n_estimators=60,
    learning_rate=0.1,
    max_depth=3,
    random_state=10,
    device="auto",
)
reg.fit(X, y)

staged = list(reg.staged_predict(X[:3]))
print("R^2 score:", reg.score(X, y))
print("Stages yielded:", len(staged))
print("Final predictions (first 3):", staged[-1])

On this page