Skip to Content
OchreML
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 device string ("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, and score consume contiguous float64 buffers 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

ParameterTypeDefaultDescription
n_estimatorsint50Maximum number of boosting iterations / base estimators.
learning_ratefloat1.0Weight applied to each classifier at each boosting iteration.
max_depthint1Maximum depth of each decision tree base estimator (1 = decision stump).
random_stateint | NoneNoneRandom seed controlling tie-breaking and base learner randomness.
devicestr | NoneNoneExecution device ("auto", "cpu", "cuda:0", "wgpu", "tpu"). Defaults to ochreml.get_default_device().

Attributes

AttributeTypeDescription
classes_np.ndarray | None1D float64 array of unique class labels discovered during fit.
estimator_weights_np.ndarray1D float64 array of SAMME weights assigned to each fitted base estimator.
estimator_errors_np.ndarray1D float64 array of weighted classification 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) -> AdaBoostClassifierBuild a boosted classifier from (X, y) with optional sample weights.
predictpredict(X) -> np.ndarrayPredict class labels for samples in X.
predict_probapredict_proba(X) -> np.ndarrayPredict class probabilities of shape (n_samples, n_classes).
decision_functiondecision_function(X) -> np.ndarrayCompute weighted ensemble decision scores of shape (n_samples,) or (n_samples, n_classes).
scorescore(X, y) -> floatReturn mean classification accuracy on (X, y).
savesave(path: str) -> NoneSave the fitted boosting model to a binary .dit file.
loadAdaBoostClassifier.load(path: str, device: str | None = None)Load a fitted classifier from a .dit file.
toto(device: str) -> AdaBoostClassifierMove 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])

On this page