Skip to content

Commit 78003ac

Browse files
Diogo Bastosmfeurer
authored andcommitted
Refactor hyperparameter name 'max_depth' to 'max_depth_factor' (#590)
* refactor: changed max_depth parameter name * Changed the parameter name 'max_depth' to 'max_depth_factor' in the decision_tree.py file in both the 'regression/decision_tree' and 'classification/decision_tree' folders. Related to: #569 * fix: fixed invalid parameter name * Fixed invalid parameter name of 'max_depth_factor' to 'max_depth' while initializing the sklearn's DecisionTreeClassifier and DecisionTreeRegressor. Related to: #569 * refactor: added line breaks * Added line breaks in decision_tree.py files to enforce the rule that no line should have more then 79 characters. Related to: #569 * fix: removed trailing whitespaces * fix: replaced tabs with spaces * fix: fixed identation * fix: fixed identation * fix: reverted incorrect Makefile changes * fix: reverted Makefile change
1 parent 5cc546d commit 78003ac

File tree

2 files changed

+24
-20
lines changed

2 files changed

+24
-20
lines changed

autosklearn/pipeline/components/classification/decision_tree.py

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,13 @@
1313

1414

1515
class DecisionTree(AutoSklearnClassificationAlgorithm):
16-
def __init__(self, criterion, max_features, max_depth,
16+
def __init__(self, criterion, max_features, max_depth_factor,
1717
min_samples_split, min_samples_leaf, min_weight_fraction_leaf,
1818
max_leaf_nodes, min_impurity_decrease, class_weight=None,
1919
random_state=None):
2020
self.criterion = criterion
2121
self.max_features = max_features
22-
self.max_depth = max_depth
22+
self.max_depth_factor = max_depth_factor
2323
self.min_samples_split = min_samples_split
2424
self.min_samples_leaf = min_samples_leaf
2525
self.max_leaf_nodes = max_leaf_nodes
@@ -34,12 +34,14 @@ def fit(self, X, y, sample_weight=None):
3434

3535
self.max_features = float(self.max_features)
3636
# Heuristic to set the tree depth
37-
if check_none(self.max_depth):
38-
max_depth = self.max_depth = None
37+
if check_none(self.max_depth_factor):
38+
max_depth_factor = self.max_depth_factor = None
3939
else:
4040
num_features = X.shape[1]
41-
self.max_depth = int(self.max_depth)
42-
max_depth = max(1, int(np.round(self.max_depth * num_features, 0)))
41+
self.max_depth_factor = int(self.max_depth_factor)
42+
max_depth_factor = max(
43+
1,
44+
int(np.round(self.max_depth_factor * num_features, 0)))
4345
self.min_samples_split = int(self.min_samples_split)
4446
self.min_samples_leaf = int(self.min_samples_leaf)
4547
if check_none(self.max_leaf_nodes):
@@ -51,7 +53,7 @@ def fit(self, X, y, sample_weight=None):
5153

5254
self.estimator = DecisionTreeClassifier(
5355
criterion=self.criterion,
54-
max_depth=max_depth,
56+
max_depth=max_depth_factor,
5557
min_samples_split=self.min_samples_split,
5658
min_samples_leaf=self.min_samples_leaf,
5759
max_leaf_nodes=self.max_leaf_nodes,
@@ -92,8 +94,8 @@ def get_hyperparameter_search_space(dataset_properties=None):
9294

9395
criterion = CategoricalHyperparameter(
9496
"criterion", ["gini", "entropy"], default_value="gini")
95-
max_depth = UniformFloatHyperparameter(
96-
'max_depth', 0., 2., default_value=0.5)
97+
max_depth_factor = UniformFloatHyperparameter(
98+
'max_depth_factor', 0., 2., default_value=0.5)
9799
min_samples_split = UniformIntegerHyperparameter(
98100
"min_samples_split", 2, 20, default_value=2)
99101
min_samples_leaf = UniformIntegerHyperparameter(
@@ -103,7 +105,7 @@ def get_hyperparameter_search_space(dataset_properties=None):
103105
max_leaf_nodes = UnParametrizedHyperparameter("max_leaf_nodes", "None")
104106
min_impurity_decrease = UnParametrizedHyperparameter('min_impurity_decrease', 0.0)
105107

106-
cs.add_hyperparameters([criterion, max_features, max_depth,
108+
cs.add_hyperparameters([criterion, max_features, max_depth_factor,
107109
min_samples_split, min_samples_leaf,
108110
min_weight_fraction_leaf, max_leaf_nodes,
109111
min_impurity_decrease])

autosklearn/pipeline/components/regression/decision_tree.py

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,12 @@
1111
from autosklearn.util.common import check_none
1212

1313
class DecisionTree(AutoSklearnRegressionAlgorithm):
14-
def __init__(self, criterion, max_features, max_depth,
14+
def __init__(self, criterion, max_features, max_depth_factor,
1515
min_samples_split, min_samples_leaf, min_weight_fraction_leaf,
1616
max_leaf_nodes, min_impurity_decrease, random_state=None):
1717
self.criterion = criterion
1818
self.max_features = max_features
19-
self.max_depth = max_depth
19+
self.max_depth_factor = max_depth_factor
2020
self.min_samples_split = min_samples_split
2121
self.min_samples_leaf = min_samples_leaf
2222
self.max_leaf_nodes = max_leaf_nodes
@@ -29,12 +29,14 @@ def fit(self, X, y, sample_weight=None):
2929
from sklearn.tree import DecisionTreeRegressor
3030

3131
self.max_features = float(self.max_features)
32-
if check_none(self.max_depth):
33-
max_depth = self.max_depth = None
32+
if check_none(self.max_depth_factor):
33+
max_depth_factor = self.max_depth_factor = None
3434
else:
3535
num_features = X.shape[1]
36-
self.max_depth = int(self.max_depth)
37-
max_depth = max(1, int(np.round(self.max_depth * num_features, 0)))
36+
self.max_depth_factor = int(self.max_depth_factor)
37+
max_depth_factor = max(
38+
1,
39+
int(np.round(self.max_depth_factor * num_features, 0)))
3840
self.min_samples_split = int(self.min_samples_split)
3941
self.min_samples_leaf = int(self.min_samples_leaf)
4042
if check_none(self.max_leaf_nodes):
@@ -46,7 +48,7 @@ def fit(self, X, y, sample_weight=None):
4648

4749
self.estimator = DecisionTreeRegressor(
4850
criterion=self.criterion,
49-
max_depth=max_depth,
51+
max_depth=max_depth_factor,
5052
min_samples_split=self.min_samples_split,
5153
min_samples_leaf=self.min_samples_leaf,
5254
max_leaf_nodes=self.max_leaf_nodes,
@@ -80,8 +82,8 @@ def get_hyperparameter_search_space(dataset_properties=None):
8082
criterion = CategoricalHyperparameter('criterion',
8183
['mse', 'friedman_mse', 'mae'])
8284
max_features = Constant('max_features', 1.0)
83-
max_depth = UniformFloatHyperparameter(
84-
'max_depth', 0., 2., default_value=0.5)
85+
max_depth_factor = UniformFloatHyperparameter(
86+
'max_depth_factor', 0., 2., default_value=0.5)
8587
min_samples_split = UniformIntegerHyperparameter(
8688
"min_samples_split", 2, 20, default_value=2)
8789
min_samples_leaf = UniformIntegerHyperparameter(
@@ -91,7 +93,7 @@ def get_hyperparameter_search_space(dataset_properties=None):
9193
min_impurity_decrease = UnParametrizedHyperparameter(
9294
'min_impurity_decrease', 0.0)
9395

94-
cs.add_hyperparameters([criterion, max_features, max_depth,
96+
cs.add_hyperparameters([criterion, max_features, max_depth_factor,
9597
min_samples_split, min_samples_leaf,
9698
min_weight_fraction_leaf, max_leaf_nodes,
9799
min_impurity_decrease])

0 commit comments

Comments
 (0)