2

Hello I would like to construct a Confusion Matrix as described here: confusion matrix using only LaTeX code

enter image description here

Unfortunately I have failed to adjust the code :(

I got as close as this thread, but the labels "actual" & "predicted" are not really centred. enter image description here

Can somebody help?

  • 1
    Welcome to TeX.SE. It looks like you've simply copied the image from the other answer. Can you at least expand that source to get the 3x3 matrix? We like to see at least some sort of attempt on this site. – Teepeemm Aug 27 at 11:53
2

Hope the below code meets your requirement:

\documentclass{book}
\usepackage{rotating,multirow}
\begin{document}

\begin{tabular}{cc|c|c|c|}
&\multicolumn{1}{c}{}&\multicolumn{3}{c}{\textbf{Source1}}\\
&\multicolumn{1}{c}{}&\multicolumn{1}{c}{\textbf{A}}
&\multicolumn{1}{c}{\textbf{B}}
&\multicolumn{1}{c}{\textbf{C}}\\
\cline{3-5}
\multicolumn{1}{c}{\multirow{3}{*}{\rotatebox{90}{\textbf{Source2}}}}
&\textbf{A} &0.1 &0.3 &0.5\\
\cline{3-5}
&\textbf{B} &0.5 &0.2 &0.1\\
\cline{3-5}
&\textbf{C} &0.4 &0.7 &0.2\\
\cline{3-5}
\end{tabular}

\end{document}

And the output is:

enter image description here

2

After a coffee break I was able to answer it. :D

Still thank you for your help!!

enter image description here

\documentclass[11pt]{report}
\usepackage{graphicx}
\usepackage[printonlyused,nohyperlinks]{acronym}

%%%% Confusion Matrix Body %%%%
\newcommand\MyBox[1]{%
    \fbox{\parbox[c][3cm][c]{3cm}{\centering #1}}%
    % Size of boxes
}
\newcommand\MyVBox[1]{%
    \parbox[c][1cm][c]{1cm}{\centering\bfseries #1}%
}  
\newcommand\MyHBox[2][\dimexpr3cm+2\fboxsep\relax]{%
    \parbox[c][1cm][c]{#1}{\centering\bfseries #2}%
}  
\newcommand\MyTBox[4]{%
    \MyVBox{#1}
    \MyBox{#2}\hspace*{-\fboxrule}%
    \MyBox{#3}\par\vspace{-\fboxrule}%
}  
%%%%
\newcommand*\rot{\rotatebox{90}}

\begin{document}

\begin{acronym}
    \acro{TP}{True Positive}
    \acro{FP}{False Positive}
    \acro{TN}{True Negative}
    \acro{FN}{False Negative}
\end{acronym}

\begin{figure}
    \begin{center}
    {

        \offinterlineskip

        \raisebox{-6cm}[0pt][0pt]{
            \parbox[c][5pt][c]{1cm}{\hspace{-4.1cm}\rot{\textbf{Actual}}\\[20pt]}}\par

        \hspace*{1cm}\MyHBox[\dimexpr3.4cm+6\fboxsep\relax]{Predicted}\par

        \hspace*{1cm}\MyHBox{Cancelled}\MyHBox{Not Cancelled}\par

        \MyTBox{\rot{Cancelled}}{\ac{TP}}{\ac{FN}}

        \MyTBox{\rot{Not Cancelled}}{\ac{FP}}{\ac{TN}}

    }
\end{center}

\end{figure}
\end{document}

Because I am interested is there a better way to make Actual aligned in the middle with the same distance as Predicted. (My solution was try and error)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.