Editor

Accuracy for Each Group

Intermediate · Write the code · from Computing Bias and Crowdsourcing: Unfair Data, Shared Effort

From the lesson: How can programmers reduce bias?

Programmers should act to reduce bias in the algorithms they build. Otherwise computing repeats existing human biases, only faster and for millions of people at once. Steps that help: - Build diverse teams, and ask a wide range of users for feedback while designing.

Read this part of the lesson

A face-unlock feature was tested on many people. Each result is a tuple (group, was_correct). Write accuracy_by_group(results) that returns a dictionary mapping each group to the percent of its results that were correct, rounded to 1 decimal place. Groups should appear in the order they first show up in results.

accuracy_by_group([("A", True), ("A", True), ("B", False), ("B", True)])
->  {"A": 100.0, "B": 50.0}
def accuracy_by_group(results):
# results is a list of (group, was_correct) tuples
accuracy = {}
return accuracy

What Check runs

Your code runs first, then each of these lines, and 2 more that stay hidden. The output must match exactly.

RunsExpected output
print(accuracy_by_group([("A", True), ("A", True), ("B", False), ("B", True)])){'A': 100.0, 'B': 50.0}
print(accuracy_by_group([("teens", True), ("adults", True), ("teens", False), ("adults", True), ("teens", False)])){'teens': 33.3, 'adults': 100.0}

More Computing Bias exercises

All Python exercises · 50 practice problems