Components / AI Data Visualization
AI Confusion Matrix
A confusion matrix visualization for AI classification models with accuracy percentages and color intensity.
Components / AI Data Visualization
A confusion matrix visualization for AI classification models with accuracy percentages and color intensity.
F1 Score
0.962
Precision
98.4%
Install the core libraries required for this component.
npm install react"use client";
import React from "react";
const matrix = [
{ p: 0.94, actual: "Cat", pred: "Cat" },
{ p: 0.02, actual: "Cat", pred: "Dog" },
{ p: 0.88, actual: "Dog", pred: "Dog" },
{ p: 0.04, actual: "Dog", pred: "Robot" },
{ p: 0.96, actual: "Robot", pred: "Robot" },
];
export default function AIConfusionMatrix() {
const getOpac = (val: number) => Math.max(0.1, val);
return (
<div className="rounded-xl border border-zinc-200 dark:border-zinc-800 bg-white dark:bg-zinc-950 p-6 shadow-sm w-full max-w-sm mx-auto overflow-hidden">
<div className="flex items-center justify-between mb-8">
<h3 className="text-xs font-black text-zinc-500 uppercase tracking-widest">Classification Confusion Matrix</h3>
</div>
<div className="grid grid-cols-4 gap-1">
{/* Labels */}
<div />
{["Cat", "Dog", "Robot"].map(l => <div key={l} className="text-[10px] font-black text-zinc-400 text-center uppercase tracking-tighter">{l}</div>)}
{["Cat", "Dog", "Robot"].map((row, i) => (
<React.Fragment key={row}>
<div className="text-[10px] font-black text-zinc-400 flex items-center h-12 uppercase tracking-tighter">{row}</div>
{[0, 1, 2].map((col) => {
const val = i === col ? 0.9 - i * 0.05 : 0.05 + Math.random() * 0.1;
return (
<div
key={col}
className="aspect-square w-12 rounded-sm relative flex items-center justify-center"
style={{ backgroundColor: `rgba(16, 185, 129, ${getOpac(val)})` }}
>
<span className="text-[10px] font-black text-zinc-900 dark:text-white">{(val * 100).toFixed(0)}</span>
</div>
);
})}
</React.Fragment>
))}
</div>
<div className="mt-8 flex items-center justify-between">
<div className="space-y-1">
<p className="text-[10px] font-bold text-zinc-400 uppercase tracking-tighter">F1 Score</p>
<p className="text-sm font-black text-zinc-900 dark:text-zinc-100">0.962</p>
</div>
<div className="space-y-1 text-right">
<p className="text-[10px] font-bold text-zinc-400 uppercase tracking-tighter">Precision</p>
<p className="text-sm font-black text-emerald-500">98.4%</p>
</div>
</div>
</div>
);
} "use client";
import React from "react";
const matrix = [
{ p: 0.94, actual: "Cat", pred: "Cat" },
{ p: 0.02, actual: "Cat", pred: "Dog" },
{ p: 0.88, actual: "Dog", pred: "Dog" },
{ p: 0.04, actual: "Dog", pred: "Robot" },
{ p: 0.96, actual: "Robot", pred: "Robot" },
];
export default function AIConfusionMatrix() {
const getOpac = (val: number) => Math.max(0.1, val);
return (
<div className="rounded-xl border border-zinc-200 dark:border-zinc-800 bg-white dark:bg-zinc-950 p-6 shadow-sm w-full max-w-sm mx-auto overflow-hidden">
<div className="flex items-center justify-between mb-8">
<h3 className="text-xs font-black text-zinc-500 uppercase tracking-widest">Classification Confusion Matrix</h3>
</div>
<div className="grid grid-cols-4 gap-1">
{/* Labels */}
<div />
{["Cat", "Dog", "Robot"].map(l => <div key={l} className="text-[10px] font-black text-zinc-400 text-center uppercase tracking-tighter">{l}</div>)}
{["Cat", "Dog", "Robot"].map((row, i) => (
<React.Fragment key={row}>
<div className="text-[10px] font-black text-zinc-400 flex items-center h-12 uppercase tracking-tighter">{row}</div>
{[0, 1, 2].map((col) => {
const val = i === col ? 0.9 - i * 0.05 : 0.05 + Math.random() * 0.1;
return (
<div
key={col}
className="aspect-square w-12 rounded-sm relative flex items-center justify-center"
style={{ backgroundColor: `rgba(16, 185, 129, ${getOpac(val)})` }}
>
<span className="text-[10px] font-black text-zinc-900 dark:text-white">{(val * 100).toFixed(0)}</span>
</div>
);
})}
</React.Fragment>
))}
</div>
<div className="mt-8 flex items-center justify-between">
<div className="space-y-1">
<p className="text-[10px] font-bold text-zinc-400 uppercase tracking-tighter">F1 Score</p>
<p className="text-sm font-black text-zinc-900 dark:text-zinc-100">0.962</p>
</div>
<div className="space-y-1 text-right">
<p className="text-[10px] font-bold text-zinc-400 uppercase tracking-tighter">Precision</p>
<p className="text-sm font-black text-emerald-500">98.4%</p>
</div>
</div>
</div>
);
} Internal functions used to handle component logic.
| Function | Parameters |
|---|---|
| getOpac() | val: number |
| AIConfusionMatrix() | None |
All variable declarations found in this component.
| Name | Kind | Value |
|---|---|---|
| matrix | | [ |
| val | | i === col ? 0.9 - i * 0.05 : 0.05 + Math.random() * 0.1 |
Every JSX/HTML tag used in this component, with usage count and source.
| Tag | Count | Type | Source |
|---|---|---|---|
| <React.Fragment> | 1× | | react |
| <div> | 10× | | Native HTML |
| <h3> | 1× | | Native HTML |
| <p> | 4× | | Native HTML |
| <span> | 1× | | Native HTML |