HomeVolumesContestsSectionsForumsUsersPrintHelpAbout

Volumes > Array and Matrices > problem:


50517 - Confusion Matrix

Guest
• Review clarifications (1)

Volume problems

• 50529 - Row to Table
• 50786 - Top Question
• 50788 - Eight Puzzle
• 50499 - Table to Row
• 50823 - Secret Number
• 50853 - Parking Place
• 50496 - Falling Bricks
• 50802 - Comparing Exams
• 50517 - Confusion Matrix
• 50866 - Buy the cheapest
• 50785 - Swimming Contest
• 51011 - Decoding the Path
• 50515 - Lines - Revisited
• 50999 - Overlapping Trips
• 50507 - Sequential Numbers
• 50449 - The biggest result
• 50434 - Row Min Subtraction

Feedback

If you notice incorrect translations in Contester, please let author know.

Time limit 2000/4000/4000/4000 ms. Memory limit 65000/65000/65000/65000 Kb.
Question by Ibrahim Mesecan.

Confusion Matrix

In artificial intelligence, especially in supervised learning, performance of an algorithm is measured using a specific table layout which is called Confusion matrix. On the rows of the table actual object classes are listed. And on the columns the predicted object classes are listed. For example the table below lists confusion matrix for positive and negative objects.

The table on the right tells that there are actually 8 positive and 6 negative objects. The algorithm has predicted 5 positives and 4 negatives correctly. But it has predicted 3 positives as negative and 2 negatives as positive.

Question: Write a program that is going to read actual and predicted classes of n objects. Then your program will show the confusion matrix.

Input specification
You will be given two integers in the beginning: the number of classes (k) and the number of queries (n). Then in the following k lines, you will be k strings (which are in alphabetical order): the object classes where each class label can have at most 20 chars (only 26 English letters). The in the following n lines you will be given two strings.

  • Actual object class
  • Detected class
where 1 ≤ n ≤ 5,000 and 1 ≤ k ≤ 60.

Output specification
Show k-by-k matrix.

Sample Input I
3 10
Apple
Orange
Pear
Pear Pear
Orange Orange
Apple Orange
Orange Orange
Pear Pear
Pear Pear
Orange Pear
Apple Apple
Orange Orange
Apple Pear
Sample Output I
1 1 1
0 3 1
0 0 3


Для отправки решений необходимо выполнить вход.

www.contester.ru