2022年12月15日 星期四

Python and ML Dictionary

scores={} 
for leaf_size in candidate_max_leaf_nodes: 
    my_mae = get_mae(leaf_size , train_X, val_X, train_y, val_y) 
    scores[leaf_size]=my_mae
 #下面一樣功能 
scores = {leaf_size: get_mae(leaf_size, train_X, val_X, train_y, val_y) for leaf_size in candidate_max_leaf_nodes}

print([scores.get(i) for i in candidate_max_leaf_nodes])
print(scores)
best_tree_size =min(scores , key=scores.get)
print(best_tree_size)