|
6 | 6 | [](https://pepy.tech/project/treeplot) |
7 | 7 | [](https://pepy.tech/project/treeplot/month) |
8 | 8 | [](https://www.buymeacoffee.com/erdogant) |
| 9 | +[](https://erdogant.github.io/treeplot/) |
9 | 10 | <!---[](https://erdogant.github.io/donate/?currency=USD&amount=5)--> |
10 | 11 |
|
11 | 12 | * ``treeplot`` is Python package to easily plot the tree derived from models such as decisiontrees, randomforest and xgboost. |
12 | 13 | Developing explainable machine learning models is becoming more important in many domains. The most popular and classical explainable models are still tree based. Think of decision trees or random forest. The tree that is learned can be visualized and then explained. However, it can be a challange to simply plot the tree. Think of configuration issues with dot files, path locations to graphviz, differences across operating systems, differences across editors such as jupyter notebook, colab, spyder etc. This frustration led to this library, an easy way to plot the decision trees 🌲. It works for Random-forest, decission trees, xgboost and gradient boosting models. Under the hood it makes many checks, downloads graphviz, sets the path and then plots the tree. |
13 | 14 |
|
14 | | -# |
15 | | -**Star this repo if you like it! ⭐️** |
16 | | -# |
17 | | - |
18 | 15 | ### Functions in treeplot |
19 | 16 |
|
20 | 17 | Treeplot can plot the tree for Random-forest, decission trees, xgboost and gradient boosting models: |
21 | | - * treeplot.plot() : Generic function to plot the tree of any of the four models with default settings |
22 | | - * treeplot.randomforest() : Plot the randomforest model. Parameters can be specified. |
23 | | - * treeplot.xgboost() : Plot the xgboost model. Parameters can be specified. |
24 | | - * treeplot.import_example('iris') : Import example dataset |
| 18 | + * .plot : Generic function to plot the tree of any of the four models with default settings |
| 19 | + * .randomforest : Plot the randomforest model. Parameters can be specified. |
| 20 | + * .xgboost : Plot the xgboost model. Parameters can be specified. |
| 21 | + * .import_example('iris') : Import example dataset |
25 | 22 |
|
26 | | -### Installation |
27 | | -* Install treeplot from PyPI (recommended). treeplot is compatible with Python 3.6+ and runs on Linux, MacOS X and Windows. |
28 | | -* It is distributed under the MIT license. |
| 23 | +# |
| 24 | +**⭐️ Star this repo if you like it ⭐️** |
| 25 | +# |
29 | 26 |
|
30 | | -#### Quick Start |
31 | | -``` |
| 27 | +#### Install treeplot from PyPI |
| 28 | + |
| 29 | +```bash |
32 | 30 | pip install treeplot |
33 | 31 | ``` |
34 | 32 |
|
35 | | - |
36 | 33 | #### Import treeplot package |
37 | | -```python |
38 | | -import treeplot |
39 | | -``` |
40 | 34 |
|
41 | | -### Example RandomForest: |
42 | 35 | ```python |
43 | | -# Load example dataset |
44 | | -X,y = treeplot.import_example() |
45 | | -# Learn model |
46 | | -from sklearn.ensemble import RandomForestClassifier |
47 | | -model = RandomForestClassifier(n_estimators=100, max_depth=2, random_state=0).fit(X, y) |
| 36 | +import treeplot as tree |
48 | 37 | ``` |
| 38 | +# |
49 | 39 |
|
50 | | -```python |
51 | | -# Make plot |
52 | | -ax = treeplot.plot(model) |
53 | | -# or directly |
54 | | -ax = treeplot.randomforest(model) |
55 | | -``` |
56 | | -<p align="center"> |
57 | | - <img src="https://github.com/erdogant/treeplot/blob/master/docs/figs/Figure_1.png" width="550" /> |
58 | | -</p> |
59 | 40 |
|
60 | | -```python |
61 | | -# If more parameters needs to be specified, use the exact function: |
62 | | -ax = treeplot.randomforest(model, export='pdf') |
63 | | -``` |
| 41 | +### [Documentation pages](https://erdogant.github.io/treeplot/) |
64 | 42 |
|
65 | | -#### Example XGboost: |
66 | | -```python |
67 | | -# Load example dataset |
68 | | -X,y = treeplot.import_example() |
69 | | -# Learn model |
70 | | -from xgboost import XGBClassifier |
71 | | -model = XGBClassifier(n_estimators=100, max_depth=2, random_state=0).fit(X, y) |
72 | | -``` |
| 43 | +On the [documentation pages](https://erdogant.github.io/treeplot/) you can find detailed information about the working of the ``treeplot`` with examples. |
73 | 44 |
|
74 | | -```python |
75 | | -# Make plot |
76 | | -ax = treeplot.plot(model) |
77 | | -# or directly |
78 | | -ax = treeplot.xgboost(model) |
79 | | -``` |
80 | | -<p align="center"> |
81 | | - <img src="https://github.com/erdogant/treeplot/blob/master/docs/figs/Figure2_xgboost_hor.png" width="550" /> |
82 | | - <img src="https://github.com/erdogant/treeplot/blob/master/docs/figs/Figure2_featimportance.png" width="350" /> |
| 45 | +<hr> |
| 46 | + |
| 47 | +### Examples |
| 48 | + |
| 49 | +# |
| 50 | + |
| 51 | +* [Example: RandomForest](https://erdogant.github.io/treeplot/pages/html/Examples.html#) |
| 52 | + |
| 53 | +<p align="left"> |
| 54 | + <a href="https://erdogant.github.io/treeplot/pages/html/Examples.html#"> |
| 55 | + <img src="https://github.com/erdogant/treeplot/blob/master/docs/figs/fig_breast_randomforest.png" width="600" /> |
| 56 | + </a> |
83 | 57 | </p> |
84 | 58 |
|
85 | | -```python |
86 | | -# If more parameters needs to be specified, use the exact function: |
87 | | -ax = treeplot.xgboost(model, plottype='vertical') |
88 | | -``` |
89 | | -<p align="center"> |
90 | | - <img src="https://github.com/erdogant/treeplot/blob/master/docs/figs/Figure2_xgboost_ver.png" width="550" /> |
| 59 | + |
| 60 | +# |
| 61 | + |
| 62 | +* [Example: XGboot](https://erdogant.github.io/treeplot/pages/html/Examples.html#xgboost) |
| 63 | + |
| 64 | +<p align="left"> |
| 65 | + <a href="https://erdogant.github.io/treeplot/pages/html/Examples.html#xgboost"> |
| 66 | + <img src="https://github.com/erdogant/treeplot/blob/master/docs/figs/fig_breast_xgboot_tree.png" width="600" /> |
| 67 | + <br> |
| 68 | + <img src="https://github.com/erdogant/treeplot/blob/master/docs/figs/fig_breast_xgboot_weights.png" width="600" /> |
| 69 | + </a> |
91 | 70 | </p> |
92 | 71 |
|
93 | 72 |
|
| 73 | +# |
| 74 | +* [Example: gradientboostingclassifier](https://erdogant.github.io/treeplot/pages/html/Examples.html#gradientboostingclassifier) |
| 75 | +# |
| 76 | +* [Example: lightbm](https://erdogant.github.io/treeplot/pages/html/Examples.html#lightbm) |
| 77 | +# |
| 78 | +* [Example: Explore other trees such as second best tree etc](https://erdogant.github.io/treeplot/pages/html/Examples.html#plot-second-best-tree-and-other-trees) |
| 79 | + |
| 80 | +<hr> |
| 81 | + |
94 | 82 | #### Maintainers |
95 | 83 | * Erdogan Taskesen, github: [erdogant](https://github.com/erdogant) |
96 | 84 |
|
97 | 85 | #### Contribute |
98 | 86 | * Contributions are welcome. |
99 | 87 | * If you wish to buy me a <a href="https://www.buymeacoffee.com/erdogant">Coffee</a> for this work, it is very appreciated :) |
100 | 88 |
|
101 | | -#### Licence |
102 | | -See [LICENSE](LICENSE) for details. |
0 commit comments