Edw*_*ard 5 python fonts xgboost
我拍了一张照片
import matplotlib.pylab as plt
%matplotlib inline
from matplotlib.pylab import rcParams
Run Code Online (Sandbox Code Playgroud)
.....我错过了xgboost的代码
xgb.plot_tree(clf, num_trees=2)
Run Code Online (Sandbox Code Playgroud)
我想增加字体大小
font = {'size' : 22}
plt.rc('font', **font)
Run Code Online (Sandbox Code Playgroud)
要么
plt.rcParams.update({'font.size': 32})
Run Code Online (Sandbox Code Playgroud)
但字体大小是如何更改xgb.plot_tree中的字体大小?
小智 10
我创建了这个辅助函数来以高分辨率导出 xgboost 树:
def plot_tree(xgb_model, filename, rankdir='UT'):
"""
Plot the tree in high resolution
:param xgb_model: xgboost trained model
:param filename: the pdf file where this is saved
:param rankdir: direction of the tree: default Top-Down (UT), accepts:'LR' for left-to-right tree
:return:
"""
import xgboost as xgb
import os
gvz = xgb.to_graphviz(xgb_model, num_trees=xgb_model.best_iteration, rankdir=rankdir)
_, file_extension = os.path.splitext(filename)
format = file_extension.strip('.').lower()
data = gvz.pipe(format=format)
full_filename = filename
with open(full_filename, 'wb') as f:
f.write(data)
Run Code Online (Sandbox Code Playgroud)
您可以通过以下调用尝试一下。我更喜欢“pdf”版本,因为它提供了可以放大到无限远的矢量图像。
plot_tree(xgb_model, 'xgboost_test_tree.pdf')
plot_tree(xgb_model, 'xgboost_test_tree.png')
plot_tree(xgb_model, 'xgboost_test_tree_LR.pdf', 'LR')
plot_tree(xgb_model, 'xgboost_test_tree_LR.png', 'LR')
Run Code Online (Sandbox Code Playgroud)
小智 9
%matplotlib inline
from xgboost import plot_tree
from matplotlib.pylab import rcParams
##set up the parameters
rcParams['figure.figsize'] = 80,50
plot_tree(finalmodel, num_trees=X)
Run Code Online (Sandbox Code Playgroud)
希望这会有所帮助,我认为你应该首先设置matplotlib参数.
归档时间: |
|
查看次数: |
4753 次 |
最近记录: |