看《机器学习实战》时,运行2-1的程序,报错AttributeError: 'dict' object has no attribute 'interitems',查了一下百度说是因为python2和python3存在兼容性问题要把iteritems改成items就ok了。
问题语句:
sortedClassCount = sorted(classCount.iteritems(),key=operator.itemgetter(1),reverse=True)
改成
sortedClassCount = sorted(classCount.items(),key=operator.itemgetter(1),reverse=True)
就解决了,问题是这本书说使用Python2编写代码,所以我也是用的Python2写的不知道怎么就错了非得写成Python3格式就好了