ValueError: Invalid decision typ

2020-07-27  本文已影响0人  菜菜鑫

使用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}{(原创,转载请注明来源)}

上一篇下一篇

猜你喜欢

热点阅读