Home Reference Source
public class | source

RandomForest

Extends:

EstimatorClassifier → RandomForest

Random forest learner. Builds multiple decision trees with a random subsample of the samples, and averages their predictions for the final prediction model.

Constructor Summary

Public Constructor
public

constructor(optionsUser: Object, bootstrap: boolean)

Constructor.

Member Summary

Public Members
public
public
public
public
public
public

trees: *[]

Method Summary

Public Methods
public

predict(X: *): *

public

predictSample(sampleFeatures: Array<number>): mixed

Make a prediction for a single sample.

public

train(X: *, y: *)

Inherited Summary

From class Estimator
public abstract

predict(X: Array<Array<number>>): Array<mixed>

Make a prediction for a data set.

public abstract

train(X: Array<Array<number>>, y: Array<mixed>)

Train the supervised learning algorithm on a dataset.

Public Constructors

public constructor(optionsUser: Object, bootstrap: boolean) source

Constructor. Initialize class members and store user-defined options.

Params:

NameTypeAttributeDescription
optionsUser Object
  • optional

User-defined options for random forest

optionsUser.numTrees number
  • optional
  • default: 10

Number of decision trees to build

optionsUser.criterion string
  • optional
  • default: 'gini'

Splitting criterion. Either 'gini', for the Gini coefficient, or 'entropy' for the Shannon entropy

optionsUser.numFeatures number | string
  • optional
  • default: 1.0

Number of features to subsample at each node. Either a number (float), in which case the input fraction of features is used (e.g., 1.0 for all features), or a string. If string, 'sqrt' and 'log2' are supported, causing the algorithm to use sqrt(n) and log2(n) features, respectively (where n is the total number of features)

optionsUser.maxDepth number
  • optional
  • default: -1

Maximum depth of each decision tree. The depth of a decision tree is the number of nodes in the longest path from the decision tree root to a leaf. It is an indicator of the complexity of the tree. Use -1 for no maximum depth

bootstrap boolean
  • optional
  • default: true

Whether to select samples for each tree by bootstrapping. If false, all samples are used for each tree. If true, n samples are drawn with replacement from the full set of samples for each tree (where n is the total number of samples)

optionsUser.numTrees number
  • optional
  • default: 10

Number of trees to construct

Public Members

public bootstrap: * source

public criterion: * source

public maxDepth: * source

public numFeatures: * source

public numTrees: * source

public trees: *[] source

Public Methods

public predict(X: *): * source

Make a prediction for a data set.

Override:

Estimator#predict

Params:

NameTypeAttributeDescription
X *

Return:

*

See:

public predictSample(sampleFeatures: Array<number>): mixed source

Make a prediction for a single sample.

Params:

NameTypeAttributeDescription
sampleFeatures Array<number>

Data point features

Return:

mixed

Prediction. Label of class with highest prevalence among k nearest neighbours

public train(X: *, y: *) source

Train the supervised learning algorithm on a dataset.

Override:

Estimator#train

Params:

NameTypeAttributeDescription
X *
y *

See: