Description
Description
For me it seems, that there is a bug going on when using max_depth and max_leaf_nodes. Whenever I use max_leaf_nodes for a DecisionTreeRegressor, the given max_depth is ignored (or at least not working as expected). When I remove the max_leaf_nodes, it seems to work.
Steps/Code to Reproduce
from sklearn.tree import DecisionTreeRegressor
X = [[52, 34, 1, 4, 305, 1, 253],
[78, 39, 1, 1, 382, 4, 304],
[241, 34, 1, 4, 1127, 4, 886]]
y = [[5152], [5635], [23940]]
mt = DecisionTreeRegressor(
max_depth = 1,
max_leaf_nodes = 99
)
mt.fit(X, y)
print(mt)
print("Number of nodes: {}".format(mt.tree_.node_count))
Expected Results
I expect a tree with a maximum of 3 nodes (the root and two leafs).
Actual Results
DecisionTreeRegressor(criterion='mse', max_depth=1, max_features=None,
max_leaf_nodes=99, min_impurity_decrease=0.0,
min_impurity_split=None, min_samples_leaf=1,
min_samples_split=2, min_weight_fraction_leaf=0.0,
presort=False, random_state=None, splitter='best')
Number of nodes: 5
Exporting the tree via export_graphviz results in this image:
Versions
System:
python: 3.6.7 | packaged by conda-forge | (default, Nov 21 2018, 02:32:25) [GCC 4.8.2 20140120 (Red Hat 4.8.2-15)]
executable: /opt/conda/bin/python
machine: Linux-4.14.79-boot2docker-x86_64-with-debian-buster-sid
BLAS:
macros: HAVE_CBLAS=None
lib_dirs: /opt/conda/lib
cblas_libs: openblas, openblas
Python deps:
pip: 19.0.1
setuptools: 40.6.3
sklearn: 0.20.1
numpy: 1.13.3
scipy: 1.1.0
Cython: 0.28.5
pandas: 0.23.4