ValueError: Invalid decision type in tree model.

使用LightGBM模型可视化时报错ValueError: Invalid decision type in tree model.

lgb.create_tree_digraph()
lgb.plot_tree()

错误定位到python-package/lightgbm/plotting.py中的271行
原因是root['decision_type']为'<=',而判断条件错误,微软官方LightGBM好像已经修正了错误,但可能是我安装版本的问题
解决方法为进入/.local/lib/python3.6/site-packages/lightgbm目录
管理员权限打开文件sudo gedit plotting.py
相关位置修改为如下代码

                if info in {'split_gain', 'internal_value', 'internal_count'}:
                    label += '\n' + info + ':' + str(root[info])
            graph.node(name, label=label)
            # if root['decision_type'] == 'no_greater':
            if root['decision_type'] == '<=':
                l_dec, r_dec = '<=', '>'
            # elif root['decision_type'] == 'is':
            elif root['decision_type'] == '=':

完美解决
参考:https://github.com/microsoft/LightGBM/pull/810/files/7e824df64a739b6818f2d10bf3dbdc2cfd7fe876

\color{red}{(原创,转载请注明来源)}

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

友情链接更多精彩内容