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

试了好多种办法都得不到解决,有没有大神指点!急
...全文
168 回复 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
回复
切换为时间正序
请发表友善的回复…
发表回复

37,743

社区成员

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

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