v2025.6.2
All Bundles

RandomForest

Random forest algorithm

forest := RandomForest->New(8);
forest->Train(0.3, data);
result := forest->Query(data);

possible := Bool->Rows(result)->As(Float);
matched := DecisionTree->Matches(result->Columns() - 1, result)->As(Float);
matched_perc := (matched / possible * 100.0)->As(Int);
"matched {$matched_perc}%"->PrintLine();

Operations

Load

Loads a saved random forest

function : Load(filename:String) ~ RandomForest

Parameters

NameTypeDescription
filenameStringfile to store to

Return

TypeDescription
RandomForestrandom forest

New

Constructor

New(num_trees:Int)

Parameters

NameTypeDescription
num_treesIntnumber of trees to generate

Query

Splits a matrix based on a list of decisions

method : public : native : Query(input:BoolMatrixRef) ~ Bool[,]

Parameters

NameTypeDescription
inputBoolMatrixRefmatrix to be split

Return

TypeDescription
Boolsplit matrix

Query

Splits a matrix based on a list of decisions

method : public : native : Query(input:Bool[,]) ~ Bool[,]

Parameters

NameTypeDescription
inputBoolmatrix to be split

Return

TypeDescription
Boolsplit matrix

Store

Saves a random forest

method : public : Store(filename:String) ~ Bool

Parameters

NameTypeDescription
filenameStringfile to save to

Return

TypeDescription
Booltrue if successful, false otherwise

Train

Calculates a list of decision splits

method : public : native : Train(split_perc:Float, input:BoolMatrixRef) ~ Nil

Parameters

NameTypeDescription
split_percFloatpercentage of data to use for training
inputBoolMatrixReftraining matrix

Train

Calculates a list of decision splits

method : public : native : Train(split_perc:Float, input:Bool[,]) ~ Nil

Parameters

NameTypeDescription
split_percFloatpercentage of data to use for training
inputBooltraining matrix