Name the Classes

Machine Learning in CodeEasy+10 XP+10

Name the Classes

A built-in dataset stores its labels as numbers: 0, 1, 2. The real names live in a separate key.

Task: write class_counts(name). name is one of "iris", "wine" or "breast_cancer".

  • Load the dataset and count how many rows have each label.
  • Return a dict that maps each label's name (a string from target_names) to its count.
  • Label number i has the name at position i of target_names.

Examples

name = "iris"
returns {'setosa': 50, 'versicolor': 50, 'virginica': 50}
name = "breast_cancer"
returns {'malignant': 212, 'benign': 357}

Hints

Solve it to unlock the solution

Once your code passes every test, a reference solution shows up here so you can compare it with yours.

solution.py
CtrlEnterto run