+1 vote
in General IT Tips by (53.0k points)
I want to generate a confusion matrix showing true positive, false positive, true negative, and false negative for binary classification. How can I construct it using latex?

1 Answer

+2 votes
by (45.3k points)
selected by
 
Best answer

You can use the following lines in your latex document to generate the confusion matrix for a binary classifier.

\documentclass{article}

\usepackage[utf8]{inputenc}

\usepackage{multirow}

\usepackage{multicol}

\begin{document}

\begin{table}[ht]

\centering

\renewcommand{\arraystretch}{1.5}

\begin{tabular}{l|l|c|c|c}

\multicolumn{2}{c}{}&\multicolumn{2}{c}{\textbf{Predicted}}&\\

\cline{3-4}

\multicolumn{2}{c|}{}&\textbf{Positive}&\textbf{Negative}&\multicolumn{1}{c}{\textbf{Total}}\\

\cline{2-4}

\multirow{2}{*}{\textbf{Actual}}& \textbf{Positive} & True Positive (TP) & False Negative (FN)  & $TP+FN$\\

\cline{2-4}

& \textbf{Negative} & False Positive (FP) & True Negative (TN) & $FP+TN$\\

\cline{2-4}

\multicolumn{1}{c}{} & \multicolumn{1}{c}{\textbf{Total}} & \multicolumn{1}{c}{$TP+FP$} & \multicolumn{    1}{c}{$FN+TN$} & \multicolumn{1}{c}{$N$}\\

\end{tabular}

\caption{Confusion matrix for binary classification}

\label{tab:confusion_matrix}

\end{table}

\end{document}

Related questions

+1 vote
1 answer
+2 votes
1 answer
+1 vote
1 answer

...