源碼def iris_type(s):? ? it = {'Iris-setosa': 0, 'Iris-versicolor': 1, 'Iris-virginica': 2}? ? return it[s]# 'sepal length', 'sepal width', 'petal length', 'petal width'iris_feature = u'花萼長度', u'花萼寬度', u'花瓣長度', u'花瓣寬度'if __name__ == "__main__":? ? mpl.rcParams['font.sans-serif'] = [u'SimHei'] ?# 黑體 FangSong/KaiTi? ? mpl.rcParams['axes.unicode_minus'] = False? ? path = '..\\10.Regression\\10.iris.data' ?# 數(shù)據(jù)文件路徑? ? data = np.loadtxt(path, dtype=float, delimiter=',', converters={4: iris_type}).astype(str)? ? x_prime, y = np.split(data, (4,), axis=1)錯(cuò)誤File "D:/machinelearning/ML/12.RandomForest/12.2.Iris_DecisionTree_Enum.py", line 12, in iris_type? ? return it[s]KeyError: b'Iris-setosa'說明使用np.loadtxt( ?).astype(str)也沒有用
2 回答

慕尼黑的夜晚無繁華
TA貢獻(xiàn)1864條經(jīng)驗(yàn) 獲得超6個(gè)贊
def iris_type(s): it = {b'Iris-setosa': 0, b'Iris-versicolor': 1, b'Iris-virginica': 2} return it[s] 已經(jīng)解決了沒? 課程《機(jī)器學(xué)習(xí)升級版III》的配套代碼,我是在Python2.7上完成的呀。
添加回答
舉報(bào)
0/150
提交
取消