Confusion matrix from scratch
Mediumboolean maskssumbuilding arrays· 20 XP
A fraud model predicts 1 (fraud) or 0 (not fraud). An interviewer asks you to build the confusion matrix without any machine learning library. The labels are illustrative.
Store a 2 by 2 array laid out as [[TN, FP], [FN, TP]]:
- TN: actual 0, predicted 0
- FP: actual 0, predicted 1
- FN: actual 1, predicted 0
- TP: actual 1, predicted 1
Expected answer
Store your answer in result.
Hints, the later questions and the answer come with Pro.
import numpy as np actual = np.array([0, 0, 1, 1, 0, 1, 0, 0, 1, 0, 1, 0]) pred = np.array([0, 1, 1, 0, 0, 1, 0, 1, 1, 0, 0, 0]) result = ...