机器学习实战-Py3.X错误合集

2017-11-02  本文已影响0人  人机分离机

零. 常见

TypeError: 'range' object doesn't support item deletion
AttributeError: 'dict' object has no attribute 'iteritems' 

二. kNN

NameError: name 'reload' is not defined
from imp import reload

四. 朴素贝叶斯

UnicodeDecodeError: 'gbk' codec can't decode byte 0xae in position 199: illegal multibyte sequence
wordList = textParse(open('email/spam/%d.txt' % i).read()
wordList = textParse(open('email/ham/%d.txt' % i).read()
需要将上面的代码更为下面这两行:
wordList = textParse(open('email/spam/%d.txt' % i, "rb").read().decode('GBK','ignore') )
wordList = textParse(open('email/ham/%d.txt' % i,  "rb").read().decode('GBK','ignore') )

因为有可能文件中存在类似“�”非法字符。
TypeError: 'range' object doesn't support item deletion
AttributeError: 'dict' object has no attribute 'iteritems'

五. Logistic回归

TypeError: 'numpy.float64' object cannot be interpreted as an integer

这里是因为numpy版本问题,更改版本解决

pip install -U numpy==1.11.0
TypeError: 'range' object doesn't support item deletion
AttributeError: 'numpy.ndarray' object has no attribute 'getA'
plotBestFit(weights)
'''
    # 矩阵变为数组,使用gradAscent时加入
    weights = wei.getA()
'''

参考来自

机器学习实战Py3.x填坑记

上一篇 下一篇

猜你喜欢

热点阅读