ensemble.RandomForestClassifier

Random forest classifier creates a set of decision trees from randomly selected subset of training set. It then aggregates the votes from different decision trees to decide the final class of the test object.

Usage

import { RandomForestClassifier } from 'machinelearn/ensemble';

const X = [[0, 0], [1, 1], [2, 1], [1, 5], [3, 2]];
const y = [0, 1, 2, 3, 7];

const randomForest = new RandomForestClassifier();
randomForest.fit(X, y);

// Results in a value such as [ '0', '2' ].
// Predictions will change as we have not set a seed value.

Constructors

Methods

Constructors


constructor

new RandomForestClassifier(__namedParameters: `object`)

Defined in ensemble/forest.ts:25

Parameters:

ParamTypeDefaultDescription
options.nEstimatornumber10Number of trees.
options.randomstatenumbernullRandom seed value for DecisionTrees

Returns: RandomForestClassifier

Methods


λ fit

Build a forest of trees from the training set (X, y).

Defined in ensemble/forest.ts:57

Parameters:

ParamTypeDefaultDescription
Xnumber[][]nullarray-like or sparse matrix of shape = [nsamples, n_features]
ynumber[]nullarray-like, shape = [nsamples] or [n_samples, n_outputs]

Returns:

void

λ fromJSON

Restore the model from a checkpoint

Defined in ensemble/forest.ts:95

Parameters:

ParamTypeDefaultDescription
options.treesany[]nullDecision trees

Returns:

void

λ predict

Predict class for X.

The predicted class of an input sample is a vote by the trees in the forest, weighted by their probability estimates. That is, the predicted class is the one with highest mean probability estimate across the trees.

Defined in ensemble/forest.ts:141

Parameters:

ParamTypeDefaultDescription
Xnumber[][]nullarray-like or sparse matrix of shape = [nsamples]

Returns:

any[]

λ toJSON

Returning the current model's checkpoint

Defined in ensemble/forest.ts:80

Returns:

ParamTypeDescription
treesany[]Decision trees