Skip to content
CampusEduX

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

Easypython
Learn the Concept: Confusion Matrix

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()).

Related Problems

  • Problem 1: Generate a Basic Confusion Matrix
    Easy · python
    Solve Problem
  • Problem 2: Visualize a Confusion Matrix as a Heatmap
    Easy · python
    Solve Problem
  • Problem 4: Build a Confusion Matrix for a 3-Class Problem
    Easy · python
    Solve Problem

Input (stdin)

Output

Run your code to see output here...