I would like to make a confusion matrix that looks like the one on the picture. How can I achive this? Thanks

Asked
Active
Viewed 770 times
2
olyashevska
- 287
2 Answers
3
Quite hard coded, but you may start with this:
% arara: pdflatex
\documentclass{article}
\usepackage{blkarray}
\usepackage{multirow}
\usepackage{graphicx}
\usepackage{mathtools}
\begin{document}
\[
\renewcommand{\arraystretch}{1.6}
\begin{blockarray}{c@{}ccc}
&&\BAmulticolumn{2}{c}{\text{observed}}\\[-2\jot]
&& 0 & 1 \\
\begin{block}{c@{\hspace{.6em}}c[cc]}
\multirow{2}{*}{\rotatebox[origin=c]{90}{predicted}} & 0 & a=1 & b=2\\
& 1 & c=3 & d=4 \\
\end{block}
\end{blockarray}
\]
\end{document}

LaRiFaRi
- 43,807
3
With {NiceMatrix} of the eponymous package.
\documentclass{article}
\usepackage{nicematrix}
\begin{document}
\renewcommand{\arraystretch}{1.2}
$\begin{NiceMatrix}
& & \Block{1-2}{\text{observed}} \
& & 0 & 1 \
\Block{2-1}{\rotate \text{predicted}}
& 0 & a=1 & b=2 \[1mm]
& 1 & c=2 & d=4
\CodeAfter
\SubMatrix[{3-3}{4-4}]
\end{NiceMatrix}$
\end{document}
F. Pantigny
- 40,250

\bordermatrixwith brackets[ ]instead of parentheses( )– barbara beeton Jul 13 '15 at 15:12