Skip to Content
OchreML
Trees, Ensembles & Boosting

AdaBoostRegressor

AdaBoost.R2 regression ensemble with weighted median prediction and configurable loss functions backed by Rust Rayon.

AdaBoostRegressor implements the AdaBoost.R2 algorithm, sequentially fitting regression trees on re-weighted bootstrap samples according to current prediction errors (linear, square, or exponential loss) and combining predictions via the weighted median across estimators. (^▽^)

Backend & Hardware Acceleration

  • CPU Rayon Execution: Sequential boosting rounds fit decision tree regressors using Rust Rayon for parallel split evaluation and weighted-median inference across samples.
  • Accelerator Fallback: Accepts any OchreML device string ("auto", "cpu", "cuda:0", "wgpu", "tpu") and automatically runs branch-heavy boosting stages on CPU Rayon.
  • Zero-Copy Buffers: fit, predict, and score accept contiguous float64 NumPy arrays directly via Python's Buffer Protocol.

Import & Signature

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

AdaBoostRegressor(
    n_estimators: int = 50,
    learning_rate: float = 1.0,
    loss: str = "linear",
    max_depth: int = 3,
    random_state: Optional[int] = None,
    device: Optional[str] = None,
)

Parameters

ParameterTypeDefaultDescription
n_estimatorsint50Maximum number of estimators at which boosting terminates.
learning_ratefloat1.0Weight applied to each regressor at each boosting iteration.
lossstr"linear"Loss function used when updating sample weights: "linear", "square", or "exponential".
max_depthint3Maximum depth of each decision tree base estimator.
random_stateint | NoneNoneRandom seed controlling weighted resampling at each boosting iteration.
devicestr | NoneNoneExecution device ("auto", "cpu", "cuda:0", "wgpu", "tpu"). Defaults to ochreml.get_default_device().

Attributes

AttributeTypeDescription
estimator_weights_np.ndarray1D float64 array of AdaBoost.R2 weights for each fitted base regressor.
estimator_errors_np.ndarray1D float64 array of weighted regression errors for each boosting stage.
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) -> AdaBoostRegressorBuild a boosted regressor from (X, y) with optional sample weights.
predictpredict(X) -> np.ndarrayPredict continuous target values via weighted median across base trees.
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.
loadAdaBoostRegressor.load(path: str, device: str | None = None)Load a fitted regressor from a .dit file.
toto(device: str) -> AdaBoostRegressorMove the estimator execution target to device.

Example

import numpy as np
from ochreml.ensemble import AdaBoostRegressor

rng = np.random.default_rng(11)
X = rng.uniform(-2.0, 2.0, size=(120, 2))
y = 1.5 * X[:, 0] ** 2 - 0.8 * X[:, 1]

ada = AdaBoostRegressor(
    n_estimators=40,
    learning_rate=0.8,
    loss="square",
    max_depth=3,
    random_state=11,
    device="auto",
)
ada.fit(X, y)

print("R^2 score:", ada.score(X, y))
print("Fitted estimators:", len(ada.estimator_weights_))
print("Sample predictions:", ada.predict(X[:4]))

On this page