machine learing in action(機器學習)中 代碼因爲python2出錯的地方

因爲這本書是用python2寫的有些地方和python有一點不一樣,因而報錯的地方或是有些小問題,記錄下來。一直更新。

1. UnicodeDecodeError: ‘gbk’ codec can’t decode byte 0x80 in position 205: illegal multibyte sequence
不能解碼gbk的內容,修改如下:
file= open(‘order.log’,‘rb’)
類似問題
TypeError: write() argument must be str, not bytes
open(‘文件路徑’,‘wb’)

2.RuntimeWarning: Glyph missing from current font. font.set_text(s, 0, flags=flags)
找不到字體
plt.rcParams[‘font.sans-serif’]=[‘SimHei’] #顯示中文標籤

3.’range’ object doesn’t support item deletion
該句代碼爲del(trainingSet[randIndex])
把前面的 trainingSet = range(50) 轉化爲 trainingSet = list(range(50))因爲python在range返回的是range對象,不是數組

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章