CART决策树运行到最后产生IndexError: list index out of range错误,跪求大神指点!

阿黄king 2020-03-16 09:12:47
from IPython.display import Image  
dot_data = tree.export_graphviz(clf, out_file=None,
feature_names=feature.columns.tolist(),
class_names=target_names,
filled=True, rounded=True,
special_characters=True,node_ids=True,rotate=True,label='all')
graph = pydotplus.graph_from_dot_data(dot_data.replace('\n','').replace('helvetica', '"Microsoft YaHei"'))
Image(graph.create_png())
这是我最后的一个代码块,然后运行之后就报错了,错误如下
IndexError                                Traceback (most recent call last)
<ipython-input-225-760bece3996a> in <module>
4 class_names=target_names,
5 filled=True, rounded=True,
----> 6 special_characters=True,node_ids=True,rotate=True,label='all')
7 graph = pydotplus.graph_from_dot_data(dot_data.replace('\n','').replace('helvetica', '"Microsoft YaHei"'))
8 Image(graph.create_png())

~\Anaconda3\lib\site-packages\sklearn\tree\export.py in export_graphviz(decision_tree, out_file, max_depth, feature_names, class_names, label, filled, leaves_parallel, impurity, node_ids, proportion, rotate, rounded, special_characters, precision)
457
458 # Now recurse the tree and add node & edge attributes
--> 459 recurse(decision_tree.tree_, 0, criterion=decision_tree.criterion)
460
461 # If required, draw leaf nodes at same depth as each other

~\Anaconda3\lib\site-packages\sklearn\tree\export.py in recurse(tree, node_id, criterion, parent, depth)
377 if left_child != _tree.TREE_LEAF:
378 recurse(tree, left_child, criterion=criterion, parent=node_id,
--> 379 depth=depth + 1)
380 recurse(tree, right_child, criterion=criterion, parent=node_id,
381 depth=depth + 1)

~\Anaconda3\lib\site-packages\sklearn\tree\export.py in recurse(tree, node_id, criterion, parent, depth)
334 out_file.write('%d [label=%s'
335 % (node_id,
--> 336 node_to_str(tree, node_id, criterion)))
337
338 if filled:

~\Anaconda3\lib\site-packages\sklearn\tree\export.py in node_to_str(tree, node_id, criterion)
299 node_string += 'class = '
300 if class_names is not True:
--> 301 class_name = class_names[np.argmax(value)]
302 else:
303 class_name = "y%s%s%s" % (characters[1],

IndexError: list index out of range

试了好多种办法都得不到解决,有没有大神指点!急
...全文
190 回复 打赏 收藏 转发到动态 举报
写回复
用AI写文章
回复
切换为时间正序
请发表友善的回复…
发表回复
【重要提示】本资源设置为0积分下载,若非0积分请勿轻易下载 亲爱的CSDN用户: 首先感谢你点进这个资源页面。我需要提前说明一个重要情况: 本资源原本已设置为“0积分下载”,即作者希望完全免费共享。但CSDN平台有时会根据文件的下载热度、文件大小、用户权限等因素,自动将部分资源的积分调整为非0数值(如1积分、2积分、5积分等)。这是平台系统的自动行为,而非作者本人的设定。 因此,如果你当前看到该资源的下载所需积分不是0(例如显示为1、2、3……),请谨慎决定是否下载。 如果你按照非0积分支付并下载后发现资源内容不符合预期、链接失效,或者实际上该资源本应是免费的,作者无法为此承担积分损失或退还操作。强烈建议:仅在页面显示为0积分时进行下载。 另外,本资源描述中并未直接提供具体的下载地址或外部链接,因为它本身是一个通过CSDN官方上传通道提交的文件/内容包。如果你看到描述中没有外部网盘地址,这是正常的——资源文件应通过CSDN内置的“下载”按钮获取。若因平台积分显示异常导致你支付了积分,请优先联系CSDN客服咨询积分退还政策,作者没有权限修改平台自动设定的积分值。 感谢你的理解与支持。技术分享本应开放,但受限于平台规则,特此提醒如上。祝学习进步!

37,741

社区成员

发帖
与我相关
我的任务
社区描述
JavaScript,VBScript,AngleScript,ActionScript,Shell,Perl,Ruby,Lua,Tcl,Scala,MaxScript 等脚本语言交流。
社区管理员
  • 脚本语言(Perl/Python)社区
  • WuKongSecurity@BOB
加入社区
  • 近7日
  • 近30日
  • 至今

试试用AI创作助手写篇文章吧