Download lecture-03/assets/ConfusionMatrix-CloAXvtZ.js from DeepLearning-VT/DeepLearning_2026: direct link, hf CLI and curl.
- Browser
- Download file 5.93 kB
-
https://huggingface.co/spaces/DeepLearning-VT/DeepLearning_2026/resolve/main/lecture-03/assets/ConfusionMatrix-CloAXvtZ.js
- Command line
-
hf download hf://spaces/DeepLearning-VT/DeepLearning_2026/lecture-03/assets/ConfusionMatrix-CloAXvtZ.js
-
curl -L -o ConfusionMatrix-CloAXvtZ.js https://huggingface.co/spaces/DeepLearning-VT/DeepLearning_2026/resolve/main/lecture-03/assets/ConfusionMatrix-CloAXvtZ.js
5.93 kB
| import{B as e,C as t,Ct as n,H as r,S as i,St as a,T as o,_ as s,b as c,bt as l,d as u,dt as d,et as f,f as p,g as m,m as h,v as g,y as _,yt as v}from"./modules/shiki-CJZsCeMT.js";import{t as y}from"./_plugin-vue_export-helper-BDNMzG2s.js";import{n as b}from"./slidev/context-DB-9afGB.js";import{t as x}from"./WidgetFrame-DHgK6j2H.js";import{t as S}from"./StepButton-DD4XxENU.js";var C=[`viewBox`],w=[`x`],T=[`y`,`transform`],E={class:`dl-cm__head`},D=[`x`,`y`],O=[`x`,`y`],k={class:`dl-cm__cells`},ee=[`aria-label`,`onClick`,`onKeydown`],te=[`x`,`y`],ne=[`x`,`y`],re={class:`dl-cm__facts`},ie={class:`dl-cm__note`},A={class:`dl-cmm`},j={class:`is-digit`},M={class:`dl-cmm__bar`},N=10,P=28,F=26,I=30,L=y(o({__name:`ConfusionMatrix`,props:{mode:{default:`matrix`}},setup(o){let{$slidev:y,$nav:L,$clicksContext:ae,$clicks:oe,$page:se,$renderContext:ce,$frontmatter:le}=b(),R=[[976,0,0,0,0,1,3,0,0,0],[0,1128,3,0,0,0,0,2,2,0],[2,3,1012,4,0,0,0,8,3,0],[0,0,4,988,0,9,0,0,6,3],[0,0,2,0,962,0,3,0,0,15],[0,0,0,11,0,872,4,0,5,0],[5,2,0,0,2,6,943,0,0,0],[0,4,9,0,0,0,0,1007,0,8],[2,0,3,6,0,8,0,0,951,4],[0,0,0,2,16,0,0,7,3,981]],z=o,B=R.map(e=>e.reduce((e,t)=>e+t,0)),V=Array.from({length:N},(e,t)=>R.reduce((e,n)=>e+n[t],0)),H=B.reduce((e,t)=>e+t,0),U=Array.from({length:N},(e,t)=>R[t][t]).reduce((e,t)=>e+t,0),W=Array.from({length:N},(e,t)=>{let n=R[t][t],r=B[t]-n,i=V[t]-n,a=n/(n+i),o=n/(n+r);return{digit:t,tp:n,fn:r,fp:i,precision:a,recall:o,f1:2*a*o/(a+o),support:B[t]}}),G=Math.min(...W.map(e=>e.f1)),K=Math.max(...W.map(e=>e.fn+e.fp)),q={precision:W.reduce((e,t)=>e+t.precision,0)/N,recall:W.reduce((e,t)=>e+t.recall,0)/N,f1:W.reduce((e,t)=>e+t.f1,0)/N},J=d(!1),Y=d({r:9,c:4}),X=Math.max(...R.flatMap((e,t)=>e.filter((e,n)=>n!==t))),Z=m(()=>R.flatMap((e,t)=>e.map((e,n)=>({r:t,c:n,v:e,x:F+n*29.5,y:I+t*29.5,diag:t===n,pct:100*e/B[t],tint:t===n?1:e/X})))),Q={w:325,h:345},ue=m(()=>Y.value?Z.value.find(e=>e.r===Y.value.r&&e.c===Y.value.c)??null:null),de=m(()=>{let e=ue.value;return e?e.diag?`${e.v} of the ${B[e.r]} images of a ${e.r} were classified correctly — that is recall for class ${e.r}, ${(100*e.v/B[e.r]).toFixed(1)}%.`:e.v===0?`The model never mistook a ${e.r} for a ${e.c}. Most of this matrix is zero, which is the point: the errors live in a handful of cells.`:`${e.v} images of a true ${e.r} were predicted as ${e.c}. That is ${(100*e.v/B[e.r]).toFixed(1)}% of all the ${e.r}s in the test set.`:`Click a cell. A row is one true digit, a column is what the model said.`});function $(e){return`${(100*e).toFixed(1)}%`}function fe(e){return e.toString().replace(/\B(?=(\d{3})+(?!\d))/g,`,`)}return(o,d)=>{let m=S,y=x;return z.mode===`matrix`?(e(),g(y,{key:0,"max-width":`34rem`},{controls:f(()=>[t(m,{label:J.value?`row %`:`counts`,variant:J.value?`primary`:`ghost`,onClick:d[0]||=e=>J.value=!J.value},null,8,[`label`,`variant`]),t(m,{label:`the 4/9 pair`,variant:`ghost`,onClick:d[1]||=e=>Y.value={r:9,c:4}}),t(m,{label:`clear`,variant:`ghost`,onClick:d[2]||=e=>Y.value=null})]),readout:f(()=>[s(`div`,re,[s(`span`,null,[d[3]||=i(`accuracy `,-1),s(`strong`,null,n($(v(U)/v(H))),1)]),s(`span`,null,n(v(H)-v(U))+` mistakes in `+n(fe(v(H)))+` images`,1)]),s(`div`,ie,n(de.value),1)]),default:f(()=>[(e(),c(`svg`,{class:`dl-cm`,viewBox:`0 0 ${Q.w} ${Q.h}`,preserveAspectRatio:`xMidYMid meet`,role:`img`,"aria-label":`A 10 by 10 confusion matrix for MNIST`},[s(`text`,{class:`dl-cm__axis`,x:173.5,y:12,"text-anchor":`middle`},`predicted`,8,w),s(`text`,{class:`dl-cm__axis`,x:10,y:177.5,"text-anchor":`middle`,transform:`rotate(-90 10 177.5)`},`true`,8,T),s(`g`,E,[(e(),c(h,null,r(N,e=>s(`text`,{key:`hc${e}`,x:F+(e-1)*29.5+P/2,y:25,"text-anchor":`middle`},n(e-1),9,D)),64)),(e(),c(h,null,r(N,e=>s(`text`,{key:`hr${e}`,x:21,y:I+(e-1)*29.5+P/2+3.5,"text-anchor":`end`},n(e-1),9,O)),64))]),s(`g`,k,[(e(!0),c(h,null,r(Z.value,t=>(e(),c(`g`,{key:`${t.r}-${t.c}`,class:l({"is-diag":t.diag,"is-zero":t.v===0,"is-picked":Y.value&&Y.value.r===t.r&&Y.value.c===t.c}),tabindex:`0`,role:`button`,"aria-label":`true ${t.r}, predicted ${t.c}: ${t.v}`,onClick:e=>Y.value={r:t.r,c:t.c},onKeydown:[u(p(e=>Y.value={r:t.r,c:t.c},[`prevent`]),[`enter`]),u(p(e=>Y.value={r:t.r,c:t.c},[`prevent`]),[`space`])]},[s(`rect`,{x:t.x,y:t.y,width:P,height:P,rx:`2`,style:a(t.diag?void 0:{fill:`color-mix(in srgb, var(--dl-danger) ${Math.round(t.tint*78)}%, var(--dl-surface))`})},null,12,te),t.v>0?(e(),c(`text`,{key:0,x:t.x+P/2,y:t.y+P/2+3.5,"text-anchor":`middle`},n(J.value?t.pct<1?t.pct.toFixed(1):t.pct.toFixed(0):t.v),9,ne)):_(`v-if`,!0)],42,ee))),128))])],8,C))]),_:1})):(e(),g(y,{key:1,"max-width":`42rem`},{readout:f(()=>[...d[6]||=[s(`div`,{class:`dl-cm__note`},` Precision asks "when it said 9, was it right?"; recall asks "of the real 9s, how many did it find?". Class 9 is worst on both, and the bar says why: 28 nines missed and 30 other digits wrongly called nine. The bars are counts from zero — a bar chart of numbers between 0.97 and 0.99 would need a truncated axis to show anything. `,-1)]]),default:f(()=>[s(`table`,A,[d[5]||=s(`thead`,null,[s(`tr`,null,[s(`th`,null,`digit`),s(`th`,null,`support`),s(`th`,null,`precision`),s(`th`,null,`recall`),s(`th`,null,`F1`),s(`th`,null,`errors (missed + false)`)])],-1),s(`tbody`,null,[(e(!0),c(h,null,r(v(W),t=>(e(),c(`tr`,{key:t.digit,class:l({"is-worst":t.f1===v(G)})},[s(`td`,j,n(t.digit),1),s(`td`,null,n(t.support),1),s(`td`,null,n(t.precision.toFixed(3)),1),s(`td`,null,n(t.recall.toFixed(3)),1),s(`td`,null,n(t.f1.toFixed(3)),1),s(`td`,null,[s(`span`,M,[s(`span`,{style:a({width:`${100*(t.fn+t.fp)/v(K)}%`})},null,4)]),s(`small`,null,n(t.fn)+` + `+n(t.fp),1)])],2))),128))]),s(`tfoot`,null,[s(`tr`,null,[d[4]||=s(`td`,{colspan:`2`},`macro average`,-1),s(`td`,null,n(q.precision.toFixed(3)),1),s(`td`,null,n(q.recall.toFixed(3)),1),s(`td`,null,n(q.f1.toFixed(3)),1),s(`td`,null,`accuracy `+n($(v(U)/v(H))),1)])])])]),_:1}))}}}),[[`__scopeId`,`data-v-dde135ea`]]);export{L as t}; |