Core machine learning types: the seedable Random generator, Matrix2D linear algebra and activations, matrix reference holders, the NeuralNetwork and CSV-backed MatrixReader. Compile with -lib ml.
RandomForestClassifier
A forest of continuous-feature classification trees: each is fitted to a bootstrap sample of the rows and considers a sample of the features at every node, and the scores are averaged. RandomForest above is built on the binary-feature DecisionTree, so continuous data must be binned before it can be used. This is built on DecisionTreeClassifier and splits on thresholds directly. Both kinds of sampling matter, for different reasons. Bootstrapping the rows and sampling the features decorrelates the trees, which is what makes the average better than any single tree. Sampling the features is also the cheapest thing available on build time: the split search dominates and is linear in the features tried, so the default of sqrt(features) is roughly that speedup over trying all of them. Deterministic: the same seed rebuilds the same forest, so a result can be reproduced rather than merely repeated.
Example
forest := RandomForestClassifier->New(100, 8, 5, 42);
forest->Fit(x_train, y_train);
scores := forest->PredictScore(x_test);
recall := Metrics->RecallAtFpr(scores, y_test, 0.001);Operations
Fit #
Grows the forest.
method : public : Fit(X:Float[,], y:Bool[]) ~ BoolParameters
| Name | Type | Description |
|---|---|---|
| X | Float | rows x features, continuous |
| y | Bool | one label per row, true for the positive class |
Return
| Type | Description |
|---|---|
| Bool | true when every tree was built |
GetTreeCount #
How many trees were grown.
method : public : GetTreeCount() ~ IntReturn
| Type | Description |
|---|---|
| Int | tree count, or 0 when unfitted |
IsFitted #
Whether Fit has been called successfully.
method : public : IsFitted() ~ BoolReturn
| Type | Description |
|---|---|
| Bool | true when this forest has been grown |
New # constructor
Constructor using the usual sqrt(features) sample at each node.
New(num_trees:Int, max_depth:Int, min_samples:Int, seed:Int)Parameters
| Name | Type | Description |
|---|---|---|
| num_trees | Int | trees in the forest |
| max_depth | Int | deepest any tree may grow |
| min_samples | Int | a node with this many rows or fewer becomes a leaf |
| seed | Int | seeds bootstrapping and feature sampling |
New # constructor
Constructor with an explicit feature sample size.
New(num_trees:Int, max_depth:Int, min_samples:Int, max_features:Int, seed:Int)Parameters
| Name | Type | Description |
|---|---|---|
| num_trees | Int | trees in the forest |
| max_depth | Int | deepest any tree may grow |
| min_samples | Int | a node with this many rows or fewer becomes a leaf |
| max_features | Int | features to sample per node; 0 means sqrt(features) |
| seed | Int | seeds bootstrapping and feature sampling |