绘制单个 XGBoost 决策树 [英] Plot a Single XGBoost Decision Tree

查看:62
本文介绍了绘制单个 XGBoost 决策树的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在

解决方案

我最近遇到了同样的问题,我发现的唯一方法是尝试使用不同的图形大小(大图形仍然会变蓝.例如,绘制第四棵树,使用:

fig, ax = plt.subplots(figsize=(30, 30))xgb.plot_tree(model,num_trees = 4,ax = ax)plt.show()

要保存它,你可以这样做

plt.savefig("temp.pdf")

此外,每棵树都将两个类分开,因此您拥有与类一样多的树.

I am using method on https://machinelearningmastery.com/visualize-gradient-boosting-decision-trees-xgboost-python/ to plot a XGBoost Decision Tree

from numpy import loadtxt
from xgboost import XGBClassifier
from xgboost import plot_tree
import matplotlib.pyplot as plt
# load data
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()

As I got 150 features,the plot looks quite small for all split points,how to draw a clear one or save in local place or any other ways/ideas could clearly show this ‘tree’ is quite appreciated

解决方案

I had the same problem recently and the only way I found is by trying diffent figure size (it can still be bluery with big figure. For exemple, to plot the 4th tree, use:

fig, ax = plt.subplots(figsize=(30, 30))
xgb.plot_tree(model, num_trees=4, ax=ax)
plt.show()

To save it, you can do

plt.savefig("temp.pdf")

Also, each tree seperates two classes so you have as many tree as class.

这篇关于绘制单个 XGBoost 决策树的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆