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

阿黄king 阿黄king 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
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

试了好多种办法都得不到解决,有没有大神指点!急
...全文

相关推荐

Python数据科学实战手册:解决真实项目中的隐式陷阱

数据科学不是语法练习,而是工程化落地过程。从数据加载、清洗、连接到可视化,每个环节都存在隐式契约断裂——如Excel日期解析歧义、merge类型不匹配、Matplotlib后端失效等。这些‘看似能跑通’却导致结果不可信的问题,本质源于库间行为差异、版本静默变更与原始数据复杂性。手册聚焦pandas、numpy、scipy等核心库在生产环境中的精度陷阱、性能临界点与调试路径,提供可复现的防御性代码模式与类型安全协议。它服务于已掌握基础Python、却常在真实CSV或日志数据中卡在清洗与验证阶段的中级实践者,目

weixin_30333885

技术转移联合体在跨境技术转移中面临哪些合规要求和标准限制?.docx

技术转移联合体在跨境技术转移中面临哪些合规要求和标准限制?

BIZKEEN

省级科技管理部门在制定技术交易补贴政策时,通常优先支持哪类平台?.docx

科易网(厦门科易网科技有限公司)创立于2007年,是技术转移与科技创新数智化服务平台,拥有国家科技成果转化服务示范基地、国家技术转移示范机构等资质。平台以“AI+科技成果转化”为核心,整合成果、专利、专家、政策等多维数据,构建知识图谱与科创智能体,面向企业、政府、高校院所提供成果转化、技术需求对接、产业服务等数智化解决方案。截至目前,已服务全国企业超43万家,推动落地项目11800余项,总金额逾80亿元

BIZKEEN

水泥稳定碎石基层施工安全交底要点(含现场管控项).docx

水泥稳定碎石基层施工安全交底要点(含现场管控项)

虎王科技

普通职员月度工作总结知识笔记(结构+话术+案例).docx

普通职员月度工作总结知识笔记(结构+话术+案例)

虎王科技
评论
收藏 已收藏
分享
返回顶部
阿黄king
脚本语言 37,738 成员 34,208 内容