xgb 绘制

xgb 绘制1 windows 安装 Graphviz2 38 安装地址 https graphviz gitlab io pages Download Download windows html2 在 python 文件头添加这两行代码 importosos environ PATH os pathsep C ProgramFiles x86 Graphviz2 3

1.windows安装Graphviz2.38

安装地址:https://graphviz.gitlab.io/_pages/Download/Download_windows.html

2.在python文件头添加这两行代码

import os os.environ["PATH"] += os.pathsep + 'C:/Program Files (x86)/Graphviz2.38/bin/' # 其中C:/Program Files (x86)为安装地址,下载下来的是zip需要解压到这个位置

 

3.实例代码

def draw_xgboost(self, model):
"""
this function is able to draw xgboost tree
:param model: xgboost model
:return:
"""
self.ceate_feature_map(self.pre_data.cheat_data.columns.values.tolist()) # 特征名列表
fig, ax = plt.subplots()
fig.set_size_inches(60, 30)
xgboost.plot_tree(model, ax=ax, fmap='xgb.fmap')
fig.savefig('xgb_tree.jpg')

def ceate_feature_map(self, features):
"""
this function is able to create xgboost feature map
:param features: 数据列名
:return:
"""
outfile = open('xgb.fmap', 'w')
i = 0
for feat in features:
outfile.write('{0}\t{1}\tq\n'.format(i, feat))
i = i + 1
outfile.close()



































































 

转载于:https://www.cnblogs.com/callyblog/p/9391963.html

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请联系我们举报,一经查实,本站将立刻删除。

发布者:全栈程序员-站长,转载请注明出处:https://javaforall.net/221182.html原文链接:https://javaforall.net

(0)
上一篇 2026年3月17日 下午6:44
下一篇 2026年3月17日 下午6:44


相关推荐

  • JJF(沪苏浙皖) 4017-2025 可穿戴体温计校准规范 .pdf

    JJF(沪苏浙皖) 4017-2025 可穿戴体温计校准规范 .pdf

    2026年3月16日
    2
  • html代码大全表格_html表格代码怎么写

    html代码大全表格_html表格代码怎么写在做前台html中我们经常用到一些表格,苦逼的后台程序猿大多都简简单单的写一些标签,下面分享一下只用h5就能写出一些精美的form<formaction=“”method=“”><fieldset><legend>Insertthetitle</legend><divalign=“Cen

    2022年8月11日
    10
  • GPT-4.1 API中转站 – 2025最新免费API服务

    GPT-4.1 API中转站 – 2025最新免费API服务

    2026年3月16日
    2
  • PyCharm 调试Debug入门

    PyCharm 调试Debug入门为了摈弃 print 的暴力调试法 在 mentor 的耳濡目染下 我开始了 PyCharm 的 Debug 例程 defhelloworl print helloworld a 1b 2c 3foriinrange 5 print i a 3b 4c 5helloworld print end 1 先设置红

    2026年3月18日
    2
  • mapminmax的用法

    mapminmax的用法几个要说明的函数接口:[Y,PS]=mapminmax(X)[Y,PS]=mapminmax(X,FP)Y=mapminmax(‘apply’,X,PS)X=mapminmax(‘reverse’,Y,PS)用实例来讲解,测试数据x1=[124],x2=[523];>>[y,ps]=mapminmax(x1)y=  -1

    2022年6月17日
    109
  • HOOK编程例子

    HOOK编程例子include nbsp stdafx h include nbsp HookDll h HHOOK nbsp nbsp nbsp nbsp nbsp nbsp nbsp nbsp g hMouse nbsp nbsp NULL HINSTANCE nbsp nbsp nbsp nbsp g hInst BOOL nbsp APIENTRY nbsp DllMain nbsp HINSTANCE nbsp hinstDLL nbsp nbsp nbsp nbsp nbsp nbsp nbsp nbsp nbsp nbsp nbsp nbsp nbsp nbsp nbsp nbsp nbsp nbsp nbsp nbsp nbsp nbsp nbsp nbsp DWORD nbsp nbsp ul reason for call nbsp nbsp nbsp nbsp nbsp nbsp nbsp nbsp nbsp nbsp nbsp nbsp nbsp nbsp nbsp nbsp nbsp

    2026年3月18日
    2

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注

关注全栈程序员社区公众号