machine learing in action(機器學習實戰)中 一些代碼問題

因爲這本書是用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對象,不是數組

4.TypeError: unsupported operand type(s) for /: ‘map’ and ‘int’
在這裏插入圖片描述
5.TypeError: unhashable type: ‘matrix’
在這裏插入圖片描述
在這裏插入圖片描述
5.AttributeError: type object ‘Tk’ has no attribute ‘tk’
import tkinter(小寫)
在這裏插入圖片描述
6.AttributeError: ‘FigureCanvasTkAgg’ object has no attribute ‘show’
在這裏插入圖片描述
7.ValueError: Masked arrays must be 1-D
在這裏插入圖片描述
8.TypeError: unsupported operand type(s) for -: ‘map’ and ‘map’
在這裏插入圖片描述
9. AttributeError: ‘dict’ object has no attribute ‘hash_key’
在這裏插入圖片描述
10.TypeError: object of type ‘map’ has no len()

在這裏插入圖片描述
11. datArr = [list(map(float, line)) for line in stringArr]第13章pca
在這裏插入圖片描述

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