Bundle Machine learning library with linear regression, logistic regression, k-means clustering, and matrix operations. Designed for tabular data; supports training, prediction, and model evaluation. Compile with -lib ml.
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 # function
Loads a saved random forest
function : Load(filename:String) ~ RandomForestParameters
| Name | Type | Description |
|---|---|---|
| filename | String | file to store to |
Return
| Type | Description |
|---|---|
| RandomForest | random forest |
New # constructor
Constructor
New(num_trees:Int)Parameters
| Name | Type | Description |
|---|---|---|
| num_trees | Int | number of trees to generate |
Query # native
Splits a matrix based on a list of decisions
method : public : native : Query(input:BoolMatrixRef) ~ Bool[,]Parameters
| Name | Type | Description |
|---|---|---|
| input | BoolMatrixRef | matrix to be split |
Return
| Type | Description |
|---|---|
| Bool | split matrix |
Query # native
Splits a matrix based on a list of decisions
method : public : native : Query(input:Bool[,]) ~ Bool[,]Parameters
| Name | Type | Description |
|---|---|---|
| input | Bool | matrix to be split |
Return
| Type | Description |
|---|---|
| Bool | split matrix |
Store #
Saves a random forest
method : public : Store(filename:String) ~ BoolParameters
| Name | Type | Description |
|---|---|---|
| filename | String | file to save to |
Return
| Type | Description |
|---|---|
| Bool | true if successful, false otherwise |
Train # native
Calculates a list of decision splits
method : public : native : Train(split_perc:Float, input:BoolMatrixRef) ~ NilParameters
| Name | Type | Description |
|---|---|---|
| split_perc | Float | percentage of data to use for training |
| input | BoolMatrixRef | training matrix |