-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Add parameter
number_of_tree
to RandomForest
classifier and…
… regressor (#230) Closes #161. ### Summary of Changes Added number_of_trees parameter to initiator of random_forest_classifier and random_forest_regressor. --------- Co-authored-by: megalinter-bot <[email protected]> Co-authored-by: Alexander <[email protected]> Co-authored-by: Lars Reimann <[email protected]>
- Loading branch information
1 parent
4f08a2c
commit 414336a
Showing
4 changed files
with
72 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
17 changes: 17 additions & 0 deletions
17
tests/safeds/ml/classical/classification/test_random_forest.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import pytest | ||
from safeds.data.tabular.containers import Table | ||
from safeds.ml.classical.classification import RandomForest | ||
|
||
|
||
def test_number_of_trees_invalid() -> None: | ||
with pytest.raises(ValueError, match="The number of trees has to be greater than 0."): | ||
RandomForest(-1) | ||
|
||
|
||
def test_number_of_trees_valid() -> None: | ||
training_set = Table.from_dict({"col1": [1, 2, 3, 4], "col2": [1, 2, 3, 4]}) | ||
tagged_training_set = training_set.tag_columns(target_name="col1", feature_names=["col2"]) | ||
|
||
random_forest = RandomForest(10).fit(tagged_training_set) | ||
assert random_forest._wrapped_classifier is not None | ||
assert random_forest._wrapped_classifier.n_estimators == 10 |
17 changes: 17 additions & 0 deletions
17
tests/safeds/ml/classical/regression/test_random_forest.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import pytest | ||
from safeds.data.tabular.containers import Table | ||
from safeds.ml.classical.regression import RandomForest | ||
|
||
|
||
def test_number_of_trees_invalid() -> None: | ||
with pytest.raises(ValueError, match="The number of trees has to be greater than 0."): | ||
RandomForest(-1) | ||
|
||
|
||
def test_number_of_trees_valid() -> None: | ||
training_set = Table.from_dict({"col1": [1, 2, 3, 4], "col2": [1, 2, 3, 4]}) | ||
tagged_training_set = training_set.tag_columns(target_name="col1", feature_names=["col2"]) | ||
|
||
random_forest = RandomForest(10).fit(tagged_training_set) | ||
assert random_forest._wrapped_regressor is not None | ||
assert random_forest._wrapped_regressor.n_estimators == 10 |