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

[复制链接]
查看11 | 回复0 | 2021-1-27 06:24:30 | 显示全部楼层 |阅读模式
fromIPython.displayimportImage
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','"MicrosoftYaHei"'))
Image(graph.create_png())这是我最后的一个代码块,然后运行之后就报错了,错误如下
IndexErrorTraceback(mostrecentcalllast)
in
4class_names=target_names,
5filled=True,rounded=True,
---->6special_characters=True,node_ids=True,rotate=True,label='all')
7graph=pydotplus.graph_from_dot_data(dot_data.replace('\n','').replace('helvetica','"MicrosoftYaHei"'))
8Image(graph.create_png())
~\Anaconda3\lib\site-packages\sklearn\tree\export.pyinexport_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#Nowrecursethetreeandaddnode&edgeattributes
-->459recurse(decision_tree.tree_,0,criterion=decision_tree.criterion)
460
461#Ifrequired,drawleafnodesatsamedepthaseachother
~\Anaconda3\lib\site-packages\sklearn\tree\export.pyinrecurse(tree,node_id,criterion,parent,depth)
377ifleft_child!=_tree.TREE_LEAF:
378recurse(tree,left_child,criterion=criterion,parent=node_id,
-->379depth=depth+1)
380recurse(tree,right_child,criterion=criterion,parent=node_id,
381depth=depth+1)
~\Anaconda3\lib\site-packages\sklearn\tree\export.pyinrecurse(tree,node_id,criterion,parent,depth)
334out_file.write('%d[label=%s'
335%(node_id,
-->336node_to_str(tree,node_id,criterion)))
337
338iffilled:
~\Anaconda3\lib\site-packages\sklearn\tree\export.pyinnode_to_str(tree,node_id,criterion)
299node_string+='class='
300ifclass_namesisnotTrue:
-->301class_name=class_names[np.argmax(value)]
302else:
303class_name="y%s%s%s"%(characters[1],
IndexError:listindexoutofrange
试了好多种办法都得不到解决,有没有大神指点!急
分 -->
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

主题

0

回帖

4882万

积分

论坛元老

Rank: 8Rank: 8

积分
48824836
热门排行