@kanaries/ml
API Reference/Ensemble

AdaBoost Classifier

Learn what AdaBoost Classifier does, when to use it, and how to run AdaBoostClassifier in JavaScript or TypeScript with @kanaries/ml for browser and Node.js applications.

Algorithm overview

AdaBoostClassifier focuses on hard examples across rounds to improve classification performance over weak learners.

This algorithm is especially useful when:

  • Baseline classifiers miss difficult boundary regions.
  • You need improved recall/precision without switching to heavy models.
  • You can invest in hyperparameter tuning for learning rate and rounds.

JavaScript implementation

@kanaries/ml exposes AdaBoost classification in JavaScript so you can build stronger tabular classifiers without leaving the browser or Node.js ecosystem. It is a good option when a single weak learner is too simple, but you still want a relatively compact model with straightforward prediction logic.

That makes it attractive for product-side decision systems and TypeScript services that need boosting behavior without operating a separate Python inference path.

Quick start

AdaBoostClassifier in Python vs JavaScript / TypeScript

If you searched for "AdaBoostClassifier in JavaScript" or "AdaBoostClassifier in TypeScript", this section maps the familiar scikit-learn call to the equivalent @kanaries/ml usage for browser and Node.js runtimes.

Python
scikit-learn
from sklearn.ensemble import AdaBoostClassifier

X = [[0, 0], [1, 1], [1, 0], [0, 1]]
y = [0, 1, 1, 0]

clf = AdaBoostClassifier(n_estimators=25, learning_rate=0.5, random_state=0)
clf.fit(X, y)
pred = clf.predict([[0.9, 0.8], [0.1, 0.2]])
JavaScript / TypeScript
@kanaries/ml
import { Ensemble } from '@kanaries/ml';

const X = [[0, 0], [1, 1], [1, 0], [0, 1]];
const y = [0, 1, 1, 0];

const clf = new Ensemble.AdaBoostClassifier({ nEstimators: 25, learningRate: 0.5 });
clf.fit(X, y);
const pred = clf.predict([[0.9, 0.8], [0.1, 0.2]]);

Quick JavaScript example

import { Ensemble } from '@kanaries/ml';

const X = [[0, 0], [1, 1], [1, 0], [0, 1]];
const y = [0, 1, 1, 0];

const clf = new Ensemble.AdaBoostClassifier({ nEstimators: 25, learningRate: 0.5 });
clf.fit(X, y);
const pred = clf.predict([[0.9, 0.8], [0.1, 0.2]]);

Detailed API reference

interface AdaBoostClassifierProps {
    nEstimators?: number;
    learningRate?: number;
    randomState?: number;
}
constructor(props: AdaBoostClassifierProps = {})

Parameters

nametypedefaultdescription
nEstimatorsnumber50Number of boosting iterations
learningRatenumber1.0Weight applied to each stump
randomStatenumberundefinedSeed for reproducibility

Algorithm

AdaBoostClassifier trains decision stumps sequentially and reweights samples so that misclassified points receive more focus in subsequent rounds. It selects the number of classes automatically:

  • Binary (K = 2): discrete AdaBoost over polarity stumps with the one-sided SAMME weight update. Any two numeric labels are supported (they no longer have to be literal 0/1); classes are sorted numerically and predictions are mapped back to the original labels.
  • Multiclass (K > 2): SAMME (Zhu et al., 2009), sklearn's AdaBoostClassifier algorithm. The weak learner is a weighted-misclassification-optimal multiclass stump (each side predicts its weighted-majority class), a stump is accepted while its weighted error stays below 1 - 1/K, and alpha = learning_rate * (log((1 - err) / err) + log(K - 1)). Misclassified samples are up-weighted by exp(alpha), and predict takes the argmax of the alpha-weighted votes.

Methods

  • fit(trainX: number[][], trainY: number[]): void
  • predict(testX: number[][]): number[]
  • predictProba(testX: number[][]): number[][]
  • getFeatureImportances(): number[]

predictProba returns one column per class, ordered by the sorted class labels (for multiclass this is the normalized alpha-weighted vote share, a documented heuristic rather than a calibrated probability). getFeatureImportances covers both the binary and multiclass paths.

Implementation workflow

  1. Start with balanced preprocessing and clear label quality checks.
  2. Fit with several estimator counts and compare classification metrics.
  3. Tune threshold and class-weight strategy for product-specific tradeoffs.

JavaScript deployment notes

  • Use AdaBoost when a simple linear or shallow-tree baseline is close to useful but misses harder examples.
  • Monitor overfitting as you increase the number of estimators, especially on smaller datasets.
  • It works best on structured tabular features rather than large-scale unstructured inputs.