A majority-class baseline

Before any clever model, measure the simplest one: always predict the most common training label.

What to build

A program that builds a majority-class baseline and scores it on test labels.

Requirements

  • The baseline predicts the most common training label (ties go to the alphabetically first label).
  • Print baseline predicts L and test accuracy A, with A to 3 decimal places.

Input

Line 1: the training labels. Line 2: the test labels.

Output

Two lines.

Constraints

1 to 1000 labels in each line; labels are words.

Example

Input:

no no yes no
no yes

Output:

baseline predicts no
test accuracy 0.500

Why it works

Any useful model must beat this score: the baseline already gets right every test example of the most common class.

Examples

Example 1 · Input
no no yes no
no yes
Expected output
baseline predicts no
test accuracy 0.500
Example 2 · Input
a b
b b
Expected output
baseline predicts a
test accuracy 0.000

Prompts inside input() are ignored when checking, so input("n: ") is fine.

Hints

Hint 1

Count the training labels and find the most common one; on a tie, take the alphabetically first.

Hint 2

The baseline predicts that label for every test example.

Solution

Show one correct solution (try it yourself first)
train = input().split()
test = input().split()
counts = {}
for label in train:
    counts[label] = counts.get(label, 0) + 1
guess = min(counts, key=lambda label: (-counts[label], label))
print(f"baseline predicts {guess}")
print(f"test accuracy {test.count(guess) / len(test):.3f}")

Lesson: Machine learning in practice →