'use client' import { Grid3X3 } from 'lucide-react' interface Metrics { tp: number fp: number tn: number fn: number } interface ConfusionMatrixProps { metrics: Metrics | null } export default function ConfusionMatrix({ metrics }: ConfusionMatrixProps) { if (!metrics) { return (

Process transactions to see confusion matrix

) } const total = metrics.tp + metrics.fp + metrics.tn + metrics.fn const Cell = ({ value, label, color, description }: { value: number label: string color: string description: string }) => (

{value}

{label}

{total > 0 ? ((value / total) * 100).toFixed(1) : 0}%

) return (

Detection Performance

{/* Matrix labels */}
Predicted
{/* Y-axis label */}
Actual
{/* Matrix grid */}
{/* Column headers */}
Safe
Fraud
{/* Matrix cells */}
{/* Row: Actual Safe */}
{/* Row: Actual Fraud */}
{/* Row labels */}
Safe
Fraud
{/* Summary stats */}
F1 Score

{(() => { const precision = metrics.tp / (metrics.tp + metrics.fp) || 0 const recall = metrics.tp / (metrics.tp + metrics.fn) || 0 const f1 = 2 * (precision * recall) / (precision + recall) || 0 return f1.toFixed(3) })()}

Total

{total.toLocaleString()}

) }