All Bundles

DecisionTree

Binary decision tree algorithm

Operations

Code example:

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

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

Matches

Count matches in a column

function : Matches(index:Int, matrix:Bool[,]) ~ Int
Parameters
NameTypeDescription
indexIntcolumn index
matrixBool[,]matrix 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
matrixBool[,]matrix 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
inputBool[,]matrix to be split

Return
TypeDescription
Bool[,]split matrix

Split

Splits a matrix along the given column

function : native : Split(index:Int, input:Bool[,]) ~ Bool[,]
Parameters
NameTypeDescription
indexIntindex used to split
inputBool[,]matrix to split

Return
TypeDescription
Bool[,]split matrix

Train

Calculates a list of decision splits

function : native : Train(input:Bool[,]) ~ Vector<Split>
Parameters
NameTypeDescription
inputBool[,]training matrix

Return
TypeDescription
Vector<Split>list of decision tree splits