RandomForestClassifier
Train bootstrap decision-tree ensembles with the RandomForestClassifier JavaScript and TypeScript implementation in @kanaries/ml.
Algorithm overview
RandomForestClassifier combines many decision trees and predicts by majority vote. It is useful for nonlinear tabular classification when a single tree is too sensitive or underpowered.
JavaScript implementation
@kanaries/ml provides Ensemble.RandomForestClassifier for browser and Node.js applications. The implementation builds DecisionTreeClassifier estimators with bootstrap sampling and feature subsampling.
Quick start example
import { Ensemble } from '@kanaries/ml';
const clf = new Ensemble.RandomForestClassifier({
nEstimators: 25,
maxFeatures: 'sqrt',
randomState: 42,
});
clf.fit([[0, 0], [0, 1], [3, 3], [4, 3]], [0, 0, 1, 1]);
const pred = clf.predict([[1, 1], [4, 4]]);Detailed API reference
new Ensemble.RandomForestClassifier(props?: {
nEstimators?: number;
bootstrap?: boolean;
maxFeatures?: number | 'sqrt' | 'log2';
randomState?: number;
// plus DecisionTreeClassifier options
})Methods:
fit(trainX: number[][], trainY: number[]): voidpredict(testX: number[][]): number[]
The classifier defaults to nEstimators: 100, bootstrap: true, and maxFeatures: 'sqrt'.
Isolation Forest
Learn what Isolation Forest does, when to use it, and how to run IsolationForest in JavaScript or TypeScript with @kanaries/ml for browser and Node.js applications.
RandomForestRegressor
Predict continuous targets with tree ensembles using the RandomForestRegressor JavaScript and TypeScript implementation in @kanaries/ml.