From c66ad63b6477cb41234f3ab0d8862e6c29ee3ae5 Mon Sep 17 00:00:00 2001 From: raphaelDkhn Date: Thu, 28 Sep 2023 15:54:09 +0300 Subject: [PATCH] replace build_tree with fit --- docs/SUMMARY.md | 2 +- .../machine-learning/tree-regressor/README.md | 2 +- .../tree-regressor/tree.build_tree.md | 6 +++--- .../tree-regressor/tree.predict.md | 2 +- src/operators/ml/tree_regressor/core.cairo | 18 +++++++++--------- .../tree_regressor_fp16x16.cairo | 4 ++-- .../tree_regressor_fp32x32.cairo | 4 ++-- .../tree_regressor_fp64x64.cairo | 4 ++-- .../tree_regressor_fp8x23.cairo | 4 ++-- src/tests/ml/tree_regressor.cairo | 2 +- 10 files changed, 24 insertions(+), 24 deletions(-) diff --git a/docs/SUMMARY.md b/docs/SUMMARY.md index b1552f150..95d2e418f 100644 --- a/docs/SUMMARY.md +++ b/docs/SUMMARY.md @@ -89,7 +89,7 @@ * [nn.linear](framework/operators/neural-network/nn.linear.md) * [Machine Learning](framework/operators/machine-learning/README.md) * [Tree Regressor](framework/operators/machine-learning/tree-regressor/README.md) - * [tree.build](framework/operators/machine-learning/tree-regressor/tree.build_tree.md) + * [tree.build](framework/operators/machine-learning/tree-regressor/tree.fit.md) * [tree.predict](framework/operators/machine-learning/tree-regressor/tree.predict.md) ## 🏛 Hub diff --git a/docs/framework/operators/machine-learning/tree-regressor/README.md b/docs/framework/operators/machine-learning/tree-regressor/README.md index 1f3ccc01a..d1c9984fb 100644 --- a/docs/framework/operators/machine-learning/tree-regressor/README.md +++ b/docs/framework/operators/machine-learning/tree-regressor/README.md @@ -19,6 +19,6 @@ Orion supports currently only fixed point data types for `TreeRegressorTrait`. | function | description | | --- | --- | -| [`tree.build_tree`](tree.build\_tree.md) | Constructs a decision tree regressor based on the provided data and target values. | +| [`tree.fit`](tree.fit\_tree.md) | Constructs a decision tree regressor based on the provided data and target values. | | [`tree.predict`](tree.predict.md) | Given a set of features, predicts the target value using the constructed decision tree. | diff --git a/docs/framework/operators/machine-learning/tree-regressor/tree.build_tree.md b/docs/framework/operators/machine-learning/tree-regressor/tree.build_tree.md index 2f38f1946..d3c21616d 100644 --- a/docs/framework/operators/machine-learning/tree-regressor/tree.build_tree.md +++ b/docs/framework/operators/machine-learning/tree-regressor/tree.build_tree.md @@ -1,7 +1,7 @@ -# TreeRegressorTrait::build_tree +# TreeRegressorTrait::fit ```rust - fn build_tree(data: Span>, target: Span, max_depth: usize) -> TreeNode; + fn fit(data: Span>, target: Span, max_depth: usize) -> TreeNode; ``` Builds a decision tree based on the provided data and target values up to a specified maximum depth. @@ -44,6 +44,6 @@ fn tree_regressor_example() { ] .span(); - TreeRegressorTrait::build_tree(data, target, 3); + TreeRegressorTrait::fit(data, target, 3); } ``` diff --git a/docs/framework/operators/machine-learning/tree-regressor/tree.predict.md b/docs/framework/operators/machine-learning/tree-regressor/tree.predict.md index f732fde34..28d4a027c 100644 --- a/docs/framework/operators/machine-learning/tree-regressor/tree.predict.md +++ b/docs/framework/operators/machine-learning/tree-regressor/tree.predict.md @@ -43,7 +43,7 @@ fn tree_regressor_example() { ] .span(); - let mut tree = TreeRegressorTrait::build_tree(data, target, 3); + let mut tree = TreeRegressorTrait::fit(data, target, 3); let prediction_1 = tree .predict( diff --git a/src/operators/ml/tree_regressor/core.cairo b/src/operators/ml/tree_regressor/core.cairo index a0afba56a..1c92c419e 100644 --- a/src/operators/ml/tree_regressor/core.cairo +++ b/src/operators/ml/tree_regressor/core.cairo @@ -13,13 +13,13 @@ struct TreeNode { /// Trait /// -/// build_tree - Constructs a decision tree regressor based on the provided data and target values. +/// fit - Constructs a decision tree regressor based on the provided data and target values. /// predict - Given a set of features, predicts the target value using the constructed decision tree. trait TreeRegressorTrait { - /// # TreeRegressorTrait::build_tree + /// # TreeRegressorTrait::fit /// /// ```rust - /// fn build_tree(data: Span>, target: Span, max_depth: usize) -> TreeNode; + /// fn fit(data: Span>, target: Span, max_depth: usize) -> TreeNode; /// ``` /// /// Builds a decision tree based on the provided data and target values up to a specified maximum depth. @@ -62,11 +62,11 @@ trait TreeRegressorTrait { /// ] /// .span(); /// - /// TreeRegressorTrait::build_tree(data, target, 3); + /// TreeRegressorTrait::fit(data, target, 3); /// } /// ``` /// - fn build_tree(data: Span>, target: Span, max_depth: usize) -> TreeNode; + fn fit(data: Span>, target: Span, max_depth: usize) -> TreeNode; /// # TreeRegressorTrait::predict /// /// ```rust @@ -112,7 +112,7 @@ trait TreeRegressorTrait { /// ] /// .span(); /// - /// let mut tree = TreeRegressorTrait::build_tree(data, target, 3); + /// let mut tree = TreeRegressorTrait::fit(data, target, 3); /// /// let prediction_1 = tree /// .predict( @@ -343,7 +343,7 @@ fn best_split< (best_split_feature, best_split_value, best_prediction) } -fn build_tree< +fn fit< T, MAG, impl FFixedTrait: FixedTrait, @@ -412,10 +412,10 @@ fn build_tree< TreeNode { left: Option::Some( - BoxTrait::new(build_tree(left_data.span(), left_target.span(), depth + 1, max_depth)) + BoxTrait::new(fit(left_data.span(), left_target.span(), depth + 1, max_depth)) ), right: Option::Some( - BoxTrait::new(build_tree(right_data.span(), right_target.span(), depth + 1, max_depth)) + BoxTrait::new(fit(right_data.span(), right_target.span(), depth + 1, max_depth)) ), split_feature, split_value, diff --git a/src/operators/ml/tree_regressor/implementations/tree_regressor_fp16x16.cairo b/src/operators/ml/tree_regressor/implementations/tree_regressor_fp16x16.cairo index dc098028b..b16968c0d 100644 --- a/src/operators/ml/tree_regressor/implementations/tree_regressor_fp16x16.cairo +++ b/src/operators/ml/tree_regressor/implementations/tree_regressor_fp16x16.cairo @@ -3,10 +3,10 @@ use orion::operators::ml::tree_regressor::core; use orion::numbers::FP16x16; impl FP16x16TreeRegressor of TreeRegressorTrait { - fn build_tree( + fn fit( data: Span>, target: Span, max_depth: usize ) -> TreeNode { - core::build_tree(data, target, 0, max_depth) + core::fit(data, target, 0, max_depth) } fn predict(ref self: TreeNode, features: Span) -> FP16x16 { diff --git a/src/operators/ml/tree_regressor/implementations/tree_regressor_fp32x32.cairo b/src/operators/ml/tree_regressor/implementations/tree_regressor_fp32x32.cairo index 359142572..2379d2e1b 100644 --- a/src/operators/ml/tree_regressor/implementations/tree_regressor_fp32x32.cairo +++ b/src/operators/ml/tree_regressor/implementations/tree_regressor_fp32x32.cairo @@ -3,10 +3,10 @@ use orion::operators::ml::tree_regressor::core; use orion::numbers::{FP32x32, FP32x32Impl}; impl FP32x32TreeRegressor of TreeRegressorTrait { - fn build_tree( + fn fit( data: Span>, target: Span, max_depth: usize ) -> TreeNode { - core::build_tree(data, target, 0, max_depth) + core::fit(data, target, 0, max_depth) } fn predict(ref self: TreeNode, features: Span) -> FP32x32 { diff --git a/src/operators/ml/tree_regressor/implementations/tree_regressor_fp64x64.cairo b/src/operators/ml/tree_regressor/implementations/tree_regressor_fp64x64.cairo index 2fba8eda9..b4634ec4d 100644 --- a/src/operators/ml/tree_regressor/implementations/tree_regressor_fp64x64.cairo +++ b/src/operators/ml/tree_regressor/implementations/tree_regressor_fp64x64.cairo @@ -3,10 +3,10 @@ use orion::operators::ml::tree_regressor::core; use orion::numbers::{FP64x64, FP64x64Impl}; impl FP64x64TreeRegressor of TreeRegressorTrait { - fn build_tree( + fn fit( data: Span>, target: Span, max_depth: usize ) -> TreeNode { - core::build_tree(data, target, 0, max_depth) + core::fit(data, target, 0, max_depth) } fn predict(ref self: TreeNode, features: Span) -> FP64x64 { diff --git a/src/operators/ml/tree_regressor/implementations/tree_regressor_fp8x23.cairo b/src/operators/ml/tree_regressor/implementations/tree_regressor_fp8x23.cairo index b7ff43085..88475a574 100644 --- a/src/operators/ml/tree_regressor/implementations/tree_regressor_fp8x23.cairo +++ b/src/operators/ml/tree_regressor/implementations/tree_regressor_fp8x23.cairo @@ -3,10 +3,10 @@ use orion::operators::ml::tree_regressor::core; use orion::numbers::FP8x23; impl FP8x23TreeRegressor of TreeRegressorTrait { - fn build_tree( + fn fit( data: Span>, target: Span, max_depth: usize ) -> TreeNode { - core::build_tree(data, target, 0, max_depth) + core::fit(data, target, 0, max_depth) } fn predict(ref self: TreeNode, features: Span) -> FP8x23 { diff --git a/src/tests/ml/tree_regressor.cairo b/src/tests/ml/tree_regressor.cairo index edc8fdb1c..a4890e341 100644 --- a/src/tests/ml/tree_regressor.cairo +++ b/src/tests/ml/tree_regressor.cairo @@ -42,7 +42,7 @@ fn test_tree() { ] .span(); - let mut tree = TreeRegressorTrait::build_tree(data, target, 3); + let mut tree = TreeRegressorTrait::fit(data, target, 3); let prediction_1 = tree .predict(