‘dict_keys‘ object does not support indexing错误解决
在学习《机器学习》决策树算法,鱼类或非鱼类的案例中,也遇到了'dict_keys' object does not support indexing
查阅得知:在python3中调用dict.keys()返回的是class类型, 所以没法对dict.keys()取索引了, 可以使用list()方法将dict.keys()转换成list, 例如: list(dict.keys())
def creatDataSet():'''|不浮出水面可以生存| 是否有脚蹼 |属于鱼类|1-是----------------------|-是------------|是|2-是--------------------- |-是------------|是|3-是--------------------- |-否------------|否|4-否--------------------- |-是------------|否|5-否--------------------- |-是------------|否'''dataSet = [[1, 1, 'yes'],[1, 1, 'yes'],[1, 0, 'no'],[0, 1, 'no'],[0, 1, 'no']]list_of_trees = {'no surfacing': 'a', 'no surfacings': 'b'}lst = list(list_of_trees.keys())return dataSet, lst
同时,需要将代码中调用调用dict.keys()的方法中,改为list(),如在分类方法中:
‘dict_keys‘ object does not support indexing错误解决相关推荐
- 解决Python中字典出现“TypeError: 'dict_keys' object does not support indexing”错误
"TypeError: 'dict_keys' object does not support indexing"错误,是因为python3以后的版本改变了dict.keys的返回 ...
- python提示错误TypeError: 'dict_keys' object does not support indexing
python提示错误TypeError: 'dict_keys' object does not support indexing 原因:python2与python3之间的差异 python2中形如 ...
- python3 修改字符串的四种方法 错误 'str' object does not support item assignment 解决方法
在Python中,字符串是不可变类型,即无法直接修改字符串的某一位字符. 直接修改会报错:'str' object does not support item assignment 因此改变一个字符串 ...
- WRF安装‘can not be used when making a PIE object; recompile with -fPIC‘ 错误解决
在./compile em_real >& log.compile这一步编译的时候一直报错 搜索error发现均为PIE的问题:'can not be used when making ...
- TypeError: 'range' object doesn't support item deletion《机器学习实战》改进的随机梯度上升算法
TypeError: 'range' object doesn't support item deletion 解决办法:将dataIdex = range(m) 改为 dataIndex = lis ...
- TypeError系列之:TypeError: 'tuple' object does not support item assignment
出现这种原因的问题是:tuple元素只能读,不可以写.这是初学数据类型时容易忽略的问题. 而list类型可读可写 上代码: import numpy as npa = np.zeros([5,5])b ...
- Python 中 AttributeError: ‘NoneType‘ object has no attribute ‘X‘ 错误
文章目录 AttributeError: 'NoneType' object has no attribute 'X' 介绍 AttributeError: 'NoneType' object has ...
- 【Python】解决TypeError: 'unicode' object does not support item assignment
错误 TypeError: 'unicode' object does not support item assignment 翻译:TypeError:"unicode"对象不支 ...
- 关于出现org.hibernate.TransientObjectException: The given object has a null identifier: 错误的解决方法
关于出现org.hibernate.TransientObjectException: The given object has a null identifier: 错误的解决方法 参考文章: (1 ...
最新文章
- js callback回调的一种写法
- fpga fft项目整理
- Windows 下面 redis 发布为服务的官方方法
- 自定义loading加载
- 算法总结系列之八:复读机的故事 - 散列表.NET应用的研究(下集)
- 解决springmvc在multipart/form-data方式提交请求在过滤器Filter中获取不到参数的问题
- 给一个链表,若其中包含环,请找出该链表的环的入口结点,否则,输出null。(C++实现,非常简单明了)
- ANT的安装/配置笔记
- myeclipse(eclipse)IDE配置
- C#窗体标准计算器(上) 初级新手请多担待。
- 微博舆情挖掘需求分析
- 学习笔记(26):玩转Python-Python3基础入门-案例-快递价格计算器(1)
- ECCV2020:论文解读《Synthesize then Compare: Detecting Failures and Anomalies for Semantic Segmentation》
- 公司邮箱登录入口哪个方便,邮箱移动办公哪个最好用?
- 使用阿里云ECS服务器搭建java环境
- 窗口特征(Window Features)
- Python测试题(绘制柱状图、画出sin函数图像、散点图、pandas实现列表)
- java xml最火的的工具_几种高效的Java工具类推荐
- 上升了百分之几怎么算_上涨百分之多少怎么算
- 计算机课件制作教程ppt,电脑制作ppt详细步骤_新手制作ppt详细步骤图文教程