v2025.6.2
All Bundles

DecisionTree

Binary decision tree algorithm

data := BoolMatrixRef->New([
  [true, false, true]
  [true, false, true]
  [true, true, true]
  [true, true, true]
  [true, true, true]
  [true, true, true]
  [true, true, true]
  [true, true, true]
  [false, true, true]
  [false, true, true]
  [true, true, false]
  [true, true, false]
  [false, true, false]
  [false, true, false]
  [false, true, false]
  [false, true, false]
  [false, false, false]
  [false, false, false]
  [false, false, false]
  [false, false, false]
]);
split_data := data->Split(0.3);
training_data := split_data[0];
test_data := split_data[1];

decisions := DecisionTree->Split(training_data->Get());
result := DecisionTree->Decide(decisions, test_data->Get());

possible := result->Rows()->As(Float);
acheived := DecisionTree->Matches(2, result)->As(Float);
(acheived / possible)->PrintLine();

Operations

Gini

Calculates the Gini index

function : native : Gini(acheived:Float, goal:Float) ~ Float

Parameters

NameTypeDescription
acheivedFloatnumber acheived
goalFloatachievement target

Return

TypeDescription
FloatGini index

LoadCsv

Loads a boolean input matrix from a CSV file of 1s and 0s

function : LoadCsv(filename:String) ~ Bool[,]

Parameters

NameTypeDescription
filenameStringCSV file to load

Return

TypeDescription
Boolboolean matrix

Matches

Count matches in a column

function : Matches(index:Int, matrix:Bool[,]) ~ Int

Parameters

NameTypeDescription
indexIntcolumn index
matrixBoolmatrix matrix to inspect

Return

TypeDescription
Intnumber of matches

Mismatches

Count mismatches in a column

function : Mismatches(index:Int, matrix:Bool[,]) ~ Int

Parameters

NameTypeDescription
indexIntcolumn index
matrixBoolmatrix matrix to inspect

Return

TypeDescription
Intnumber of mismatches

Query

Splits a matrix based on a list of decisions

function : native : Query(decisions:Vector<Split>, input:Bool[,]) ~ Bool[,]

Parameters

NameTypeDescription
decisionsVector<Split>list of decisions
inputBoolmatrix to be split

Return

TypeDescription
Boolsplit matrix

Split

Splits a matrix along the given column

function : native : Split(index:Int, input:Bool[,]) ~ Bool[,]

Parameters

NameTypeDescription
indexIntindex used to split
inputBoolmatrix to split

Return

TypeDescription
Boolsplit matrix

Train

Calculates a list of decision splits

function : native : Train(input:Bool[,]) ~ Vector<Split>

Parameters

NameTypeDescription
inputBooltraining matrix

Return

TypeDescription
Vector<Split>list of decision tree splits