【发布时间】:2020-06-06 13:21:59
【问题描述】:
当我使用 min() 时,我有 python Dict。查看我的代码
scores = {leaf_size: round(get_mae(leaf_size, train_X, val_X, train_y, val_y)) for leaf_size in candidate_max_leaf_nodes}
best_tree_size = min(scores, key=scores.get)
get_mae() 只是一个计算平均绝对误差的函数。
但它显示以下错误
TypeError Traceback (most recent call last)
<ipython-input-48-aa5b1fc6e492> in <module>
8 # print(dict)
9 scores = {leaf_size: round(get_mae(leaf_size, train_X, val_X, train_y, val_y)) for leaf_size in candidate_max_leaf_nodes}
---> 10 best_tree_size = min(scores, key=scores.get)
11 # list = scores.items()
TypeError: 'int' object is not callable
【问题讨论】:
标签: python sorting dictionary min