All Bundles

RandomForest

Random forest algorithm

Operations

Code example:

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();

New

Constructor

New(num_trees:Int)
Parameters
NameTypeDescription
num_treesIntnumber of trees to generate

Load

Loads a saved random forest

function : Load(filename:String) ~ RandomForest
Parameters
NameTypeDescription
filenameStringfile to store to

Return
TypeDescription
RandomForestrandom forest

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
Bool[,]split matrix

Splits a matrix based on a list of decisions

method : public : native : Query(input:Bool[,]) ~ Bool[,]
Parameters
NameTypeDescription
inputBool[,]matrix to be split

Return
TypeDescription
Bool[,]split 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

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
inputBool[,]training matrix