在学习《机器学习》决策树算法,鱼类或非鱼类的案例中,也遇到了'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错误解决相关推荐

  1. 解决Python中字典出现“TypeError: 'dict_keys' object does not support indexing”错误

    "TypeError: 'dict_keys' object does not support indexing"错误,是因为python3以后的版本改变了dict.keys的返回 ...

  2. python提示错误TypeError: 'dict_keys' object does not support indexing

    python提示错误TypeError: 'dict_keys' object does not support indexing 原因:python2与python3之间的差异 python2中形如 ...

  3. python3 修改字符串的四种方法 错误 'str' object does not support item assignment 解决方法

    在Python中,字符串是不可变类型,即无法直接修改字符串的某一位字符. 直接修改会报错:'str' object does not support item assignment 因此改变一个字符串 ...

  4. 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 ...

  5. TypeError: 'range' object doesn't support item deletion《机器学习实战》改进的随机梯度上升算法

    TypeError: 'range' object doesn't support item deletion 解决办法:将dataIdex = range(m) 改为 dataIndex = lis ...

  6. TypeError系列之:TypeError: 'tuple' object does not support item assignment

    出现这种原因的问题是:tuple元素只能读,不可以写.这是初学数据类型时容易忽略的问题. 而list类型可读可写 上代码: import numpy as npa = np.zeros([5,5])b ...

  7. Python 中 AttributeError: ‘NoneType‘ object has no attribute ‘X‘ 错误

    文章目录 AttributeError: 'NoneType' object has no attribute 'X' 介绍 AttributeError: 'NoneType' object has ...

  8. 【Python】解决TypeError: 'unicode' object does not support item assignment

    错误 TypeError: 'unicode' object does not support item assignment 翻译:TypeError:"unicode"对象不支 ...

  9. 关于出现org.hibernate.TransientObjectException: The given object has a null identifier: 错误的解决方法

    关于出现org.hibernate.TransientObjectException: The given object has a null identifier: 错误的解决方法 参考文章: (1 ...

最新文章

  1. js callback回调的一种写法
  2. fpga fft项目整理
  3. Windows 下面 redis 发布为服务的官方方法
  4. 自定义loading加载
  5. 算法总结系列之八:复读机的故事 - 散列表.NET应用的研究(下集)
  6. 解决springmvc在multipart/form-data方式提交请求在过滤器Filter中获取不到参数的问题
  7. 给一个链表,若其中包含环,请找出该链表的环的入口结点,否则,输出null。(C++实现,非常简单明了)
  8. ANT的安装/配置笔记
  9. myeclipse(eclipse)IDE配置
  10. C#窗体标准计算器(上) 初级新手请多担待。
  11. 微博舆情挖掘需求分析
  12. 学习笔记(26):玩转Python-Python3基础入门-案例-快递价格计算器(1)
  13. ECCV2020:论文解读《Synthesize then Compare: Detecting Failures and Anomalies for Semantic Segmentation》
  14. 公司邮箱登录入口哪个方便,邮箱移动办公哪个最好用?
  15. 使用阿里云ECS服务器搭建java环境
  16. 窗口特征(Window Features)
  17. Python测试题(绘制柱状图、画出sin函数图像、散点图、pandas实现列表)
  18. java xml最火的的工具_几种高效的Java工具类推荐
  19. 上升了百分之几怎么算_上涨百分之多少怎么算
  20. 计算机课件制作教程ppt,电脑制作ppt详细步骤_新手制作ppt详细步骤图文教程

热门文章

  1. 常见股票代码开头说明大全
  2. CentOS 7 的安装教程
  3. 从战略管理角度看ERP系统信息缺失
  4. swift 隐藏状态栏_swift 同时修改状态栏和导航栏出现的问题及解决的方法
  5. python 求解高阶线性方程并画出图像
  6. 上海旅游-徐家汇教堂
  7. iOS远程推送原理及实现过程
  8. AltiumDesigner覆铜挖空技巧总结
  9. 计算机读不了硬盘分区,电脑开机后读不到硬盘怎么办
  10. 基于C++和QT实现的个人通讯录管理系统