ensemble.RandomForestClassifier
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
Properties
Methods
Constructors
constructor
⊕ RandomForestClassifier(__namedParameters: `object`)
Defined in ensemble/forest.ts:20
Parameters:
Param | Type | Default | Description |
---|---|---|---|
options.nEstimator | number | 10 | |
options.random_state | number | null |
Returns: RandomForestClassifier
Properties
▸ nEstimator
Defined in ensemble/forest.ts:12
▸ randomState
Defined in ensemble/forest.ts:13
▸ trees
Defined in ensemble/forest.ts:11
Methods
λ fit
Build a forest of trees from the training set (X, y).
Defined in ensemble/forest.ts:45
Parameters:
Param | Type | Default | Description |
---|---|---|---|
X | number[][] | null | array-like or sparse matrix of shape = [n_samples, n_features] |
y | number[] | null | array-like, shape = [n_samples] or [n_samples, n_outputs] |
Returns:
void
λ fromJSON
Restore the model from a checkpoint
Defined in ensemble/forest.ts:80
Parameters:
Param | Type | Default | Description |
---|---|---|---|
options.trees | any[] | null |
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:126
Parameters:
Param | Type | Default | Description |
---|---|---|---|
X | number[][] | null | array-like or sparse matrix of shape = [n_samples] |
Returns:
any[]
λ toJSON
Returning the current model's checkpoint
Defined in ensemble/forest.ts:65
Returns:
Param | Type | Description |
---|---|---|
trees | any[] | Decision trees |