---
title: "AdaBoost Classifier in JavaScript with @kanaries/ml"
description: "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."
canonical_url: "https://ml.kanaries.net/docs/apis/ensemble/adaboostClassifier"
markdown_url: "https://ml.kanaries.net/docs/apis/ensemble/adaboostClassifier.md"
---
# AdaBoost Classifier in JavaScript

## 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: Python and JavaScript / TypeScript

The Python example uses scikit-learn; the TypeScript example uses @kanaries/ml in browser or Node.js runtimes.

#### Python (scikit-learn)

```python
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)

```ts
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

```ts
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]]);
console.log(pred);
```

## Detailed API reference

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

### Parameters

| name         | type   | default   | description                   |
| ------------ | ------ | --------- | ----------------------------- |
| nEstimators  | number | 50        | Number of boosting iterations |
| learningRate | number | 1.0       | Weight applied to each stump  |
| randomState  | number | undefined | Seed 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.
