RegressionTree
Regression tree over numeric features: recursive binary splits chosen to minimize the children's summed squared error (variance reduction), with depth and minimum-sample stops; leaves predict the mean target. Deterministic. Also the base learner for GradientBoostedTrees.
Example
tree := RegressionTree->New(4, 2);
tree->Fit(X, y); # y is rows x 1
pred := tree->Predict([2.5]);Operations
Fit #
Fits the tree to numeric training data.
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 |
IsFitted #
Whether the tree has been fitted.
method : public : IsFitted() ~ BoolReturn
| Type | Description |
|---|---|
| Bool | true if fitted |
Load # function
Loads a fitted tree from a file.
function : Load(filename:String) ~ RegressionTreeParameters
| Name | Type | Description |
|---|---|---|
| filename | String | file to load from |
Return
| Type | Description |
|---|---|
| RegressionTree | fitted tree, or Nil on failure |
New # constructor
Creates an (unfitted) regression tree.
New(max_depth:Int, min_samples:Int)Parameters
| Name | Type | Description |
|---|---|---|
| max_depth | Int | maximum tree depth |
| min_samples | Int | minimum samples required to split a node |
Predict #
Predicts the target for a single feature row by walking the tree.
method : public : Predict(row:Float[]) ~ FloatParameters
| Name | Type | Description |
|---|---|---|
| row | Float | feature values |
Return
| Type | Description |
|---|---|
| Float | predicted target |
PredictAll #
Predicts targets for every row of an input matrix.
method : public : PredictAll(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 |
ReadFrom # function
Reads a tree previously written with WriteTo from a deserializer.
function : ReadFrom(deserializer:System.IO.Deserializer) ~ RegressionTreeParameters
| Name | Type | Description |
|---|---|---|
| deserializer | Deserializer | source deserializer |
Return
| Type | Description |
|---|---|
| RegressionTree | fitted tree, or Nil on failure |
Score #
Scores the tree on the given data (R-squared of predictions).
method : public : Score(X:Float[,], y:Float[,]) ~ FloatParameters
| Name | Type | Description |
|---|---|---|
| X | Float | feature matrix |
| y | Float | true target matrix (rows x 1) |
Return
| Type | Description |
|---|---|
| Float | R-squared, or 0.0 if not fitted or inputs are invalid |
Store #
Saves the fitted tree to a file.
method : public : Store(filename:String) ~ BoolParameters
| Name | Type | Description |
|---|---|---|
| filename | String | file to store to |
Return
| Type | Description |
|---|---|
| Bool | true if successful, false otherwise |
WriteTo #
Serializes the tree (hyperparameters + nodes in pre-order) onto an existing serializer; used by Store and by GradientBoostedTrees.
method : public : WriteTo(serializer:System.IO.Serializer) ~ NilParameters
| Name | Type | Description |
|---|---|---|
| serializer | Serializer | destination serializer |