Highlight some cells in confusion matrix

tablestikz-matrixtikz-pgf

I am trying to draw the following figure:

enter image description here

I have found an example to create the table in confusion matrix using only LaTeX code and tried to adapt the solution to my table

\documentclass{article}
%\usepackage{ifthen}
%\usetikzlibrary{matrix,calc}
\usepackage{graphicx}


\newcommand\MyBox[1]{%
  \fbox{\parbox[c][1.7cm][c]{1.7cm}{\centering #1}}%
}
\newcommand\MyVBox[1]{%
  \parbox[c][1.7cm][c]{1cm}{\centering\bfseries #1}%
}
\newcommand\MyHBox[2][\dimexpr1.7cm+2\fboxsep\relax]{%
  \parbox[c][1cm][c]{#1}{\centering\bfseries #2}%
}
\newcommand\MyTBox[4]{%
  \MyVBox{#1}\MyBox{#2}\hspace*{-\fboxrule}%
  \MyBox{#3}\hspace*{-\fboxrule}%
  \MyBox{#4}\par\vspace{-\fboxrule}
}

\begin{document}

    {
    \offinterlineskip
    % \raisebox{-5cm}[0pt][0pt]{\rotatebox[origin=c]{90}{\parbox[c][0pt][c]{1cm}{\textbf{Source2}\\[20pt]}}}\par
    % \hspace*{1cm}\MyHBox[\dimexpr5.1cm+6\fboxsep\relax]{Source1}\par
    \hspace*{1cm}\MyHBox{LH}\MyHBox{RH}\MyHBox{Other contact}\par
    \MyTBox{Type 0}{25}{0}{0}
    \MyTBox{Type 1}{1}{43}{1}
    \MyTBox{Undetected{0}{5}{-}
    }

\end{document}

and it does not compile. It shows, Missing \endcsname inserted. error.

I would like to generate the figure above and, if possible, use tikz and standalone documentclass.

Best Answer

\documentclass[tikz,border=2mm]{standalone}
\usetikzlibrary{matrix, positioning}
\begin{document}
\begin{tikzpicture}[font=\sffamily]
\matrix[matrix of nodes, nodes in empty cells, nodes={anchor=center, minimum width=3cm, minimum height=2cm, align=center, draw, text width=1.7cm}, column sep=-\pgflinewidth, row sep=-\pgflinewidth,
row 1/.style={nodes={draw=none}},
column 1/.style={nodes={draw=none}}] (A)
{
    & LH & RH & {Other contact} & {Other\\ No contact}\\
    Type 0 & 25 & 0 & 0 & 3\\
    Type 1 & 1 & 43 & 1 & 2\\
    Undetected & 0 & 5 & -- & --\\
};
\draw[green!80!black, line width=1mm] (A-2-2.north west) rectangle (A-3-3.south east);
\draw (A-2-2.north west)-- node[above right]{Real} node[below left]{AI model} (A-1-1.north west);
\end{tikzpicture}
\end{document}

enter image description here

Related Question