xgboost
代码
# plot decision tree
from numpy import loadtxt
from xgboost import XGBClassifier
from xgboost import plot_tree
import matplotlib.pyplot as plt
from graphviz import Digraph
# load data
import pydot
# print pydot.find_graphviz()
dataset = loadtxt('pima-indians-diabetes.csv', delimiter=",")
# split data into X and y
X = dataset[:, 0:8]
y = dataset[:, 8]
# fit model no training data
model = XGBClassifier()
model.fit(X, y)
# plot single tree
plot_tree(model)
plt.show()
遇到问题
You must install graphviz to plot tree
解决办法
1. https://pypi.python.org/pypi/graphviz/0.3.3
2. pip install graphviz
Here is the web page of that graphviz. This is a python package called
graphviz. Bad choice of name. You need to install the c version of
graphvis. See this web page:https://pypi.python.org/pypi/graphviz/0.3.3
From the command line, the command “dot” should work. Look into you OS to
know if it provide graphviz. If so, it will be probably the c version.Fred