ENH: Add visualization to python package

This commit is contained in:
sinhrks
2015-08-11 16:40:09 +09:00
parent a7202ee804
commit d24b36adf9
9 changed files with 311 additions and 2 deletions

View File

@@ -35,3 +35,13 @@ Scikit-Learn API
.. autoclass:: xgboost.XGBClassifier
:members:
:show-inheritance:
Plotting API
------------
.. automodule:: xgboost.plotting
.. autofunction:: xgboost.plot_importance
.. autofunction:: xgboost.plot_tree
.. autofunction:: xgboost.to_graphviz

View File

@@ -127,3 +127,27 @@ If early stopping is enabled during training, you can predict with the best iter
```python
ypred = bst.predict(xgmat,ntree_limit=bst.best_iteration)
```
Plotting
--------
You can use plotting module to plot importance and output tree.
To plot importance, use ``plot_importance``. This function requires ``matplotlib`` to be installed.
```python
xgb.plot_importance(bst)
```
To output tree via ``matplotlib``, use ``plot_tree`` specifying ordinal number of the target tree.
This function requires ``graphviz`` and ``matplotlib``.
```python
xgb.plot_tree(bst, num_trees=2)
```
When you use ``IPython``, you can use ``to_graphviz`` function which converts the target tree to ``graphviz`` instance. ``graphviz`` instance is automatically rendered on ``IPython``.
```python
xgb.to_graphviz(bst, num_trees=2)
```