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) ~ FloatParameters
| Name | Type | Description |
|---|---|---|
| acheived | Float | number acheived |
| goal | Float | achievement target |
Return
| Type | Description |
|---|---|
| Float | Gini index |
LoadCsv
Loads a boolean input matrix from a CSV file of 1s and 0s
function : LoadCsv(filename:String) ~ Bool[,]Parameters
| Name | Type | Description |
|---|---|---|
| filename | String | CSV file to load |
Return
| Type | Description |
|---|---|
| Bool | boolean matrix |
Matches
Count matches in a column
function : Matches(index:Int, matrix:Bool[,]) ~ IntParameters
| Name | Type | Description |
|---|---|---|
| index | Int | column index |
| matrix | Bool | matrix matrix to inspect |
Return
| Type | Description |
|---|---|
| Int | number of matches |
Mismatches
Count mismatches in a column
function : Mismatches(index:Int, matrix:Bool[,]) ~ IntParameters
| Name | Type | Description |
|---|---|---|
| index | Int | column index |
| matrix | Bool | matrix matrix to inspect |
Return
| Type | Description |
|---|---|
| Int | number of mismatches |
Query
Splits a matrix based on a list of decisions
function : native : Query(decisions:Vector<Split>, input:Bool[,]) ~ Bool[,]Parameters
| Name | Type | Description |
|---|---|---|
| decisions | Vector<Split> | list of decisions |
| input | Bool | matrix to be split |
Return
| Type | Description |
|---|---|
| Bool | split matrix |