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
devicestring ("auto","cpu","cuda:0","wgpu","tpu") and automatically runs branch-heavy boosting stages on CPU Rayon. - Zero-Copy Buffers:
fit,predict, andscoreaccept contiguousfloat64NumPy 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
| Parameter | Type | Default | Description |
|---|---|---|---|
n_estimators | int | 50 | Maximum number of estimators at which boosting terminates. |
learning_rate | float | 1.0 | Weight applied to each regressor at each boosting iteration. |
loss | str | "linear" | Loss function used when updating sample weights: "linear", "square", or "exponential". |
max_depth | int | 3 | Maximum depth of each decision tree base estimator. |
random_state | int | None | None | Random seed controlling weighted resampling at each boosting iteration. |
device | str | None | None | Execution device ("auto", "cpu", "cuda:0", "wgpu", "tpu"). Defaults to ochreml.get_default_device(). |
Attributes
| Attribute | Type | Description |
|---|---|---|
estimator_weights_ | np.ndarray | 1D float64 array of AdaBoost.R2 weights for each fitted base regressor. |
estimator_errors_ | np.ndarray | 1D float64 array of weighted regression errors for each boosting stage. |
feature_importances_ | np.ndarray | None | Normalized impurity-based feature importances of shape (n_features,). |
n_features_in_ | int | None | Number of features seen during fit. |
device_ | str | None | Resolved hardware device string used by the underlying Rust estimator. |
Methods
| Method | Signature | Description |
|---|---|---|
fit | fit(X, y, sample_weight=None) -> AdaBoostRegressor | Build a boosted regressor from (X, y) with optional sample weights. |
predict | predict(X) -> np.ndarray | Predict continuous target values via weighted median across base trees. |
score | score(X, y) -> float | Return the coefficient of determination R^2 on (X, y). |
save | save(path: str) -> None | Save the fitted boosting model to a binary .dit file. |
load | AdaBoostRegressor.load(path: str, device: str | None = None) | Load a fitted regressor from a .dit file. |
to | to(device: str) -> AdaBoostRegressor | Move 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]))