Want to write a confusion matrix in latex
1,500
I suspect this was translated from some other format (HTML?) by computer, so it works but in a round about manner. Also, it seems to expect a color background, as in
\documentclass{standalone}
\usepackage{xcolor}
\usepackage{colortbl}
\usepackage{multirow}
\begin{document}
\colorbox{yellow}{%
\begin{tabular}{ccclclc}
\multicolumn{2}{c}{\cellcolor[HTML]{FFFFFF}} & \multicolumn{4}{c}{Correlation Results} & \cellcolor[HTML]{FFFFFF} \\
\multicolumn{2}{c}{\multirow{-2}{*}{\cellcolor[HTML]{FFFFFF}Total Population}} & \multicolumn{2}{c}{Condition Positive (Malicious)} &
\multicolumn{2}{c}{Condition Negative (Non-Malicious)} & \multirow{-2}{*}{\cellcolor[HTML]{FFFFFF}Accuracy} \\
\multirow{2}{*}{Anomaly Detection Results} & Test Outcome Positive (Anomalous) & \multicolumn{2}{c}{True Positive} & \multicolumn{2}{c}{False Positive} & \multicolumn{1}{l}{False Discovery Rate} \\
& Test Outcome Negative (Non-Anomalous) & \multicolumn{2}{c}{False Negative} & \multicolumn{2}{c}{True Negative} & \multicolumn{1}{l}{Negative Predictive Value} \\
\multicolumn{2}{c}{\cellcolor[HTML]{FFFFFF}sgdjd} & \multicolumn{2}{c}{Recall} & \multicolumn{2}{c}{False Positive Rate (Fall-out)} &
\cellcolor[HTML]{FFFFFF}F1 Score
\end{tabular}}
\end{document}
Needless to say, this could be simplified and use a more intuitive color palette.
Related videos on Youtube
Author by
Aniss Chohra
Updated on September 08, 2020Comments
-
Aniss Chohra about 3 years
I have a program from which i get the following: - True Positives (TP). - False Positives (FP). - True Negatives (TN). - False Negatives (FN).
I want to write a code in Tex that generates me the confusion matrix that will show me these four values in addition to other metrics like: Precision, Recall, Accuracy.
I would really appreciate your help, thanks in advance.
I want something like this:
This is a sample code that I have just tried (but it gives me errors):
\begin{table}[H] \begin{tabular}{ccclclc} \multicolumn{2}{c}{\cellcolor[HTML]{FFFFFF}} & \multicolumn{4}{c} {Correlation Results} & \cellcolor[HTML]{FFFFFF} \\ \multicolumn{2}{c}{\multirow{-2}{*}{\cellcolor[HTML]{FFFFFF}Total Population}} & \multicolumn{2}{c}{Condition Positive (Malicious)} & \multicolumn{2}{c}{Condition Negative (Non-Malicious)} & \multirow{-2}{*}{\cellcolor[HTML]{FFFFFF}Accuracy} \\ & Test Outcome Positive (Anomalous) & \multicolumn{2}{c}{True Positive} & \multicolumn{2}{c}{False Positive} & \multicolumn{1}{l}{False Discovery Rate} \\ \multirow{-2}{*}{Anomaly Detection Results} & Test Outcome Negative (Non-Anomalous) & \multicolumn{2}{c}{False Negative} & \multicolumn{2}{c}{True Negative} & \multicolumn{1}{l}{Negative Predictive Value} \\ \multicolumn{2}{c}{\cellcolor[HTML]{FFFFFF}sgdjd} & \multicolumn{2}{c}{Recall} & \multicolumn{2}{c}{False Positive Rate (Fall-out)} & \cellcolor[HTML]{FFFFFF}F1 Score \end{tabular} \end{table}
-
Sebastiano about 5 yearsCan you put your full LaTeX code, please?
-
David Carlisle about 5 yearsI think you need to give more clues on what the data and required output look like
-
Aniss Chohra about 5 yearsFor now I do not have Tex any code that does what I want. This is a template of what I want at the end: en.wikipedia.org/wiki/Sensitivity_and_specificity
-
David Carlisle about 5 yearsI think you need to show (just as a text table) a full sample input for tex (ie a small sample output of your program) and an image showing the required typeset result for that input to tex (just fake output you can make in a drawing program)
-
Aniss Chohra about 5 yearsI frankly do not know how to do this in latex, but I have updated my post with an example image of what I want.
-
Admin about 5 yearsBut you could post what you have tried. Then others would not have to punch in the text from your screen shot. If you, for instance, provide a table without the colors, and ask how to add the colors, I am sure you will get a useful answer very quickly.
-
Aniss Chohra about 5 yearsI just added a sample code in my post that I have just found and tried but no success
-
Admin about 5 yearsI do not get any error when I use the preamble
\documentclass{article} \usepackage[table]{xcolor} \usepackage{multirow}
. but of course the result is not even remotely similar to your screen shot, also because the only color you use is white. -
Admin about 5 yearsWelcome to TeX.SX! Can you please expand the code snippet that you have posted to a full minimal working example. It is much easier to help you if we can start with some compilable code that illustrates your problem. A MWE should start with a
\documentclass
command, include any necessary packages and be as small as possible to demonstrate your problem. At the moment we have to guess what you are doing because we cannot compile your code from what you have posted. -
John Kormylo about 5 yearsUsing the colortbl package, the only remaining problem is that \color[HTML]{FFFFFF} is apparently white. That and the odd sgdjd.
-