RandomForestRegressor
Predict continuous targets with tree ensembles using the RandomForestRegressor JavaScript and TypeScript implementation in @kanaries/ml.
View as MarkdownAlgorithm overview
RandomForestRegressor averages predictions from many decision trees. It is useful for nonlinear numeric prediction when a single regression tree is too noisy.
JavaScript implementation
@kanaries/ml exposes Ensemble.RandomForestRegressor for JavaScript and TypeScript projects. It supports bootstrap sampling, feature subsampling, and seeded randomness.
Interactive random forest regression playground
Change the number of trees, dataset, and noise below. The prediction line is produced by a live Ensemble.RandomForestRegressor; click the chart to add another training point.
RandomForestRegressor playground
Adjust the data and model, then click the chart to add a training observation.
Quick start example
import { Ensemble } from '@kanaries/ml';
const reg = new Ensemble.RandomForestRegressor({
nEstimators: 25,
maxDepth: 4,
randomState: 7,
});
reg.fit([[0], [1], [2], [3]], [0, 1, 4, 9]);
const pred = reg.predict([[4]]);
console.log(pred);Detailed API reference
new Ensemble.RandomForestRegressor(props?: {
nEstimators?: number;
bootstrap?: boolean;
maxDepth?: number;
minSamplesSplit?: number;
maxFeatures?: number | 'sqrt' | 'log2';
randomState?: number;
})Methods:
fit(trainX: number[][], trainY: number[]): voidpredict(testX: number[][]): number[]
Defaults are nEstimators: 100, bootstrap: true, and maxFeatures: 1.0.