Skip to content

Instantly share code, notes, and snippets.

@hrzn
Created August 23, 2022 14:22
Show Gist options
  • Save hrzn/df849cef289e1e7db1ed2353220aa1e3 to your computer and use it in GitHub Desktop.
Save hrzn/df849cef289e1e7db1ed2353220aa1e3 to your computer and use it in GitHub Desktop.
# we pre-generate some of the components' names
regions_reasons_comps = list(
map(lambda t: "{} - {}".format(t[0], t[1].lower()), product(regions, reasons))
)
regions_reasons_city_comps = list(
map(
lambda t: "{} - {} - {}".format(t[0], t[1].lower(), t[2]),
product(regions, reasons, city_labels),
)
)
def measure_mae(pred):
def print_mae_on_subset(subset, name):
print(
"mean MAE on {}: {:.2f}".format(
name,
mae(
[pred[c] for c in subset],
[val[c] for c in subset],
inter_reduction=np.mean,
),
)
)
print_mae_on_subset(["Total"], "total")
print_mae_on_subset(reasons, "reasons")
print_mae_on_subset(regions, "regions")
print_mae_on_subset(regions_reasons_comps, "(region, reason)")
print_mae_on_subset(regions_reasons_city_comps, "(region, reason, city)")
measure_mae(pred)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment