From de8f9f9b5d20cbc1db7091ef95c0fcd4b96fdf8e Mon Sep 17 00:00:00 2001 From: Kevin Markham Date: Sun, 12 Apr 2020 15:55:20 -0400 Subject: [PATCH 1/5] DOC Tree pruning is now supported --- doc/modules/tree.rst | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/doc/modules/tree.rst b/doc/modules/tree.rst index ecd037d0631ac..71030e187d539 100644 --- a/doc/modules/tree.rst +++ b/doc/modules/tree.rst @@ -56,9 +56,9 @@ The disadvantages of decision trees include: - Decision-tree learners can create over-complex trees that do not generalise the data well. This is called overfitting. Mechanisms - such as pruning (not currently supported), setting the minimum - number of samples required at a leaf node or setting the maximum - depth of the tree are necessary to avoid this problem. + such as pruning, setting the minimum number of samples required + at a leaf node or setting the maximum depth of the tree are + necessary to avoid this problem. - Decision trees can be unstable because small variations in the data might result in a completely different tree being generated. From 0e2af3bad6eb2e723110ba8555e490268a88e9f8 Mon Sep 17 00:00:00 2001 From: Kevin Markham Date: Sun, 12 Apr 2020 16:01:28 -0400 Subject: [PATCH 2/5] DOC link to the plot_tree function --- doc/modules/tree.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/modules/tree.rst b/doc/modules/tree.rst index 71030e187d539..1df6cf1ad950f 100644 --- a/doc/modules/tree.rst +++ b/doc/modules/tree.rst @@ -124,7 +124,7 @@ Using the Iris dataset, we can construct a tree as follows:: >>> clf = tree.DecisionTreeClassifier() >>> clf = clf.fit(X, y) -Once trained, you can plot the tree with the plot_tree function:: +Once trained, you can plot the tree with the :func:`plot_tree` function:: >>> tree.plot_tree(clf.fit(iris.data, iris.target)) # doctest: +SKIP From dd75b372b34f6921a79c019e179d21e7c67a47b5 Mon Sep 17 00:00:00 2001 From: Kevin Markham Date: Sun, 12 Apr 2020 16:04:11 -0400 Subject: [PATCH 3/5] DOC Simplify example since clf is already fitted --- doc/modules/tree.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/modules/tree.rst b/doc/modules/tree.rst index 1df6cf1ad950f..8fb4eb588f0ea 100644 --- a/doc/modules/tree.rst +++ b/doc/modules/tree.rst @@ -127,7 +127,7 @@ Using the Iris dataset, we can construct a tree as follows:: Once trained, you can plot the tree with the :func:`plot_tree` function:: - >>> tree.plot_tree(clf.fit(iris.data, iris.target)) # doctest: +SKIP + >>> tree.plot_tree(clf) # doctest: +SKIP .. figure:: ../auto_examples/tree/images/sphx_glr_plot_iris_dtc_002.png :target: ../auto_examples/tree/plot_iris_dtc.html From 55367e8a87f13bf354bb9c8aa489ccd3bff0620b Mon Sep 17 00:00:00 2001 From: Kevin Markham Date: Sun, 12 Apr 2020 16:06:41 -0400 Subject: [PATCH 4/5] DOC Fix formatting --- doc/modules/tree.rst | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/doc/modules/tree.rst b/doc/modules/tree.rst index 8fb4eb588f0ea..5434d4bfff5d6 100644 --- a/doc/modules/tree.rst +++ b/doc/modules/tree.rst @@ -137,10 +137,7 @@ Once trained, you can plot the tree with the :func:`plot_tree` function:: We can also export the tree in `Graphviz `_ format using the :func:`export_graphviz` exporter. If you use the `conda `_ package manager, the graphviz binaries - -and the python package can be installed with - - conda install python-graphviz +and the python package can be installed with `conda install python-graphviz`. Alternatively binaries for graphviz can be downloaded from the graphviz project homepage, and the Python wrapper installed from pypi with `pip install graphviz`. From 665d4f5df0dfb79fc60b5d34990f8e495f299e2c Mon Sep 17 00:00:00 2001 From: Kevin Markham Date: Sun, 12 Apr 2020 16:09:42 -0400 Subject: [PATCH 5/5] DOC Fix example to import from non-deprecated module --- doc/modules/tree.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/modules/tree.rst b/doc/modules/tree.rst index 5434d4bfff5d6..af6fc4e1edfe9 100644 --- a/doc/modules/tree.rst +++ b/doc/modules/tree.rst @@ -185,7 +185,7 @@ of external libraries and is more compact: >>> from sklearn.datasets import load_iris >>> from sklearn.tree import DecisionTreeClassifier - >>> from sklearn.tree.export import export_text + >>> from sklearn.tree import export_text >>> iris = load_iris() >>> decision_tree = DecisionTreeClassifier(random_state=0, max_depth=2) >>> decision_tree = decision_tree.fit(iris.data, iris.target)