源码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' # 数据文件路径
data = np.loadtxt(path, dtype=float, delimiter=',', converters={4: iris_type}).astype(str)
x_prime, y = np.split(data, (4,), axis=1)
错误
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)也没有用
慕尼黑的夜晚无繁华
相关分类