Skip to content
C

Problem 3: Extract TP, TN, FP, FN from a Confusion Matrix

Easypython

Problem Description

Write a Python program that generates a confusion matrix and extracts the individual TP, TN, FP, and FN values from it directly (using array indexing, not manual recounting).

Input

Actual and predicted labels.

Output

The extracted TP, TN, FP, and FN values.

Constraints

  • Binary classification only.

Example Input

text
actual=[0,0,1,1,1], predicted=[0,1,1,1,0]

Example Output

text
TN: 1, FP: 1, FN: 1, TP: 2

Concepts Covered

confusion_matrix(), array indexing/unpacking (.ravel()).

Input (stdin)

Output

Run your code to see output here...