@kanaries/ml
API Reference/Ensemble

BaggingRegressor

Reduce regression variance with bootstrap aggregation using the BaggingRegressor JavaScript and TypeScript implementation in @kanaries/ml.

View as Markdown

Algorithm overview

BaggingRegressor fits cloned regressors on random sample subsets and averages their predictions. It is useful for reducing the variance of unstable learners such as regression trees.

JavaScript implementation

Ensemble.BaggingRegressor defaults to decision trees and can clone any registered regressor that implements fit and predict. Seedable sampling makes browser and Node.js runs reproducible.

Interactive bagging regression playground

Vary the ensemble size and sample noise to see bootstrap averaging at work. The curve is fitted live with Ensemble.BaggingRegressor and responds to observations you add.

Live browser model

BaggingRegressor playground

Adjust the data and model, then click the chart to add a training observation.

Fitted with @kanaries/ml
-3-2-10123-1.9-0.90.01.01.9feature xtarget y
prediction training holdout your points
Train RMSE0.135
Holdout RMSE0.242
Holdout R²0.707
Custom points0

Quick start example

import { Ensemble } from '@kanaries/ml';
const X = [[0], [1], [2], [3], [4]];
const y = [0, 1, 4, 9, 16];
const model = new Ensemble.BaggingRegressor({ nEstimators: 25, maxSamples: .8, randomState: 42 });
model.fit(X, y);
console.log(model.predict([[2.5]]));

Detailed API reference

Constructor options are estimator?, nEstimators? (default 10), maxSamples? (integer or fraction), bootstrap? (default true), and randomState?. Methods are fit(X, y) and predict(X).