37,743
社区成员




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