Bundle Core machine learning types: the seedable Random generator, Matrix2D linear algebra and activations, matrix reference holders, the NeuralNetwork and CSV-backed MatrixReader. Compile with -lib ml.
GradientBoostedTrees
Gradient boosted regression trees with squared-error loss: the model starts at the target mean and each stage fits a RegressionTree to the current residuals, added with a shrinkage (learning rate) factor. Deterministic.
Example
gbt := GradientBoostedTrees->New(50, 0.1, 3, 2);
gbt->Fit(X, y);
"R²={$gbt->Score(X, y)}"->PrintLine();Operations
Fit #
Fits the boosted ensemble.
method : public : Fit(X:Float[,], y:Float[,]) ~ BoolParameters
| Name | Type | Description |
|---|---|---|
| X | Float | feature matrix (rows=samples, cols=features) |
| y | Float | target matrix (rows=samples, cols=1) |
Return
| Type | Description |
|---|---|
| Bool | true if fitting succeeded |
GetTreeCount #
Gets the number of boosting stages fitted.
method : public : GetTreeCount() ~ IntReturn
| Type | Description |
|---|---|
| Int | tree count |
IsFitted #
Whether the ensemble has been fitted.
method : public : IsFitted() ~ BoolReturn
| Type | Description |
|---|---|
| Bool | true if fitted |
Load # function
Loads a fitted ensemble from a file.
function : Load(filename:String) ~ GradientBoostedTreesParameters
| Name | Type | Description |
|---|---|---|
| filename | String | file to load from |
Return
| Type | Description |
|---|---|
| GradientBoostedTrees | fitted ensemble, or Nil on failure |
New # constructor
Constructor
New(num_trees:Int, learning_rate:Float, max_depth:Int, min_samples:Int)Parameters
| Name | Type | Description |
|---|---|---|
| num_trees | Int | boosting stages |
| learning_rate | Float | shrinkage per stage (e.g. 0.1) |
| max_depth | Int | maximum depth of each tree |
| min_samples | Int | minimum samples required to split a node |
Predict #
Predicts targets for every row of an input matrix.
method : public : Predict(X:Float[,]) ~ Float[,]Parameters
| Name | Type | Description |
|---|---|---|
| X | Float | feature matrix |
Return
| Type | Description |
|---|---|
| Float | prediction matrix (rows x 1), or Nil if not fitted |