A loan model is 90% accurate overall. But is it 90% accurate for everyone? Slice the results by group and find out.
Task: write group_accuracy(groups, y_true, y_pred).
groups[i] is the group of row i, such as an age band or a country. Groups are strings.y_true and y_pred hold the real and predicted labels.Return a dict:
"overall": the accuracy over all rows,"by_group": a dict from each group to its accuracy,"worst": the group with the lowest accuracy. If several groups tie, take the one that comes first alphabetically.Round every accuracy to 3 decimal places. Compare unrounded accuracies when you choose the worst group.