Start with the simplest measure: the share of predictions that are correct.
What to build
A program that prints a classifier's accuracy and number of errors.
Requirements
- Print
accuracy P%with P to one decimal place, thenerrors E.
Input
Two lines with the same number of labels, each 0 or 1: the actual labels, then the predictions.
Output
Two lines.
Constraints
1 to 1000 labels per line.
Example
Input:
1 0 1 1 0 0 1 0
1 0 0 1 0 1 1 0
Output:
accuracy 75.0%
errors 2
Why it works
Each position is one prediction, so counting matching positions gives the number correct and the rest are errors.
Examples
Example 1 · Input
1 0 1 1 0 0 1 0 1 0 0 1 0 1 1 0
Expected output
accuracy 75.0% errors 2
Example 2 · Input
1 1 1 1
Expected output
accuracy 100.0% errors 0
Prompts inside input() are ignored when checking, so input("n: ") is fine.
Hints
Hint 1
Count the positions where the two lists agree with zip.
Hint 2
Accuracy is correct ÷ total × 100.
Solution
Show one correct solution (try it yourself first)
actual = input().split()
pred = input().split()
correct = sum(1 for a, p in zip(actual, pred) if a == p)
print(f"accuracy {100 * correct / len(actual):.1f}%")
print(f"errors {len(actual) - correct}")