Fair Shares in the Test Set

Machine Learning in CodeEasy+10 XP+10

Fair Shares in the Test Set

When you hold back test rows, you want every label to show up in the test set in the same share as in the whole dataset.

Task: write test_class_counts(name, test_size, seed). name is "iris", "wine" or "breast_cancer".

  • Load the dataset as X and y.
  • Split it with train_test_split(X, y, test_size=test_size, random_state=seed, stratify=y).
  • Return how many test rows have each label, as a list ordered by label number: [count of 0, count of 1, ...].

Examples

name = "iris"
test_size = 0.2
seed = 0
returns [10, 10, 10]
name = "wine"
test_size = 0.25
seed = 0
returns [15, 18, 12]

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