Trees, Ensembles & Boosting
AdaBoostClassifier
Adaptive Boosting classifier using SAMME weighted decision trees backed by Rust Rayon.
AdaBoostClassifier implements multi-class Adaptive Boosting (SAMME) over weighted decision tree base learners (decision stumps by default with max_depth=1). At each stage, sample weights are increased for misclassified observations so subsequent trees focus on harder examples. (^▽^)
Backend & Hardware Acceleration
- CPU Rayon Execution: Sequential boosting rounds fit weighted decision trees with parallel feature split search via Rust Rayon.
- Accelerator Fallback: Accepts any OchreML
devicestring ("auto","cpu","cuda:0","wgpu","tpu") for uniform pipeline interoperability and automatically executes branch-heavy weighted tree rounds on CPU Rayon. - Zero-Copy Buffers:
fit,predict,predict_proba,decision_function, andscoreconsume contiguousfloat64buffers directly.
Import & Signature
from ochreml.ensemble import AdaBoostClassifier
# or: from ochreml import AdaBoostClassifier
AdaBoostClassifier(
n_estimators: int = 50,
learning_rate: float = 1.0,
max_depth: int = 1,
random_state: Optional[int] = None,
device: Optional[str] = None,
)Parameters
| Parameter | Type | Default | Description |
|---|---|---|---|
n_estimators | int | 50 | Maximum number of boosting iterations / base estimators. |
learning_rate | float | 1.0 | Weight applied to each classifier at each boosting iteration. |
max_depth | int | 1 | Maximum depth of each decision tree base estimator (1 = decision stump). |
random_state | int | None | None | Random seed controlling tie-breaking and base learner randomness. |
device | str | None | None | Execution device ("auto", "cpu", "cuda:0", "wgpu", "tpu"). Defaults to ochreml.get_default_device(). |
Attributes
| Attribute | Type | Description |
|---|---|---|
classes_ | np.ndarray | None | 1D float64 array of unique class labels discovered during fit. |
estimator_weights_ | np.ndarray | 1D float64 array of SAMME weights assigned to each fitted base estimator. |
estimator_errors_ | np.ndarray | 1D float64 array of weighted classification 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) -> AdaBoostClassifier | Build a boosted classifier from (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 | Compute weighted ensemble decision scores of shape (n_samples,) or (n_samples, n_classes). |
score | score(X, y) -> float | Return mean classification accuracy on (X, y). |
save | save(path: str) -> None | Save the fitted boosting model to a binary .dit file. |
load | AdaBoostClassifier.load(path: str, device: str | None = None) | Load a fitted classifier from a .dit file. |
to | to(device: str) -> AdaBoostClassifier | Move the estimator execution target to device. |
Example
import numpy as np
from ochreml.ensemble import AdaBoostClassifier
rng = np.random.default_rng(5)
X0 = rng.normal(loc=[-1.0, 0.5], scale=0.6, size=(50, 2))
X1 = rng.normal(loc=[1.0, -0.5], scale=0.6, size=(50, 2))
X = np.vstack([X0, X1])
y = np.array([0.0] * 50 + [1.0] * 50)
ada = AdaBoostClassifier(
n_estimators=40,
learning_rate=0.8,
max_depth=1,
random_state=5,
device="auto",
)
ada.fit(X, y)
print("Accuracy:", ada.score(X, y))
print("Fitted estimators:", len(ada.estimator_weights_))
print("First 3 stage errors:", ada.estimator_errors_[:3])