【机器学习实战—第4章:基于概率论的分类方法:朴素贝叶斯】代码报错(python3)

1、报错:UnicodeDecodeError: ‘gbk’ codec can’t decode byte 0xae in position 199: illegal multibyte sequence
原因:这是文件编码的问题,文件中有非法的多字节字符。
解决办法:打开Ch04\email\ham\23.txt,找到SciFinance?,把?重新输入一下或者替换成空格即可。
2、报错:‘TypeError: ‘range’ object doesn’t support item deletion
这里写图片描述
这里写图片描述
原因:python3中range返回的是range对象,不返回数组对象。
解决办法:把 trainingSet = range(50) 改为 trainingSet = list(range(50))即可解决。

猜你喜欢

转载自blog.csdn.net/chenlin41204050/article/details/79154347