![2x2 混淆矩阵](https://linux22.com/image/400869/2x2%20%E6%B7%B7%E6%B7%86%E7%9F%A9%E9%98%B5.png)
答案1
喝完咖啡休息一下后我就能回答了。:D
仍然谢谢你的帮助!!
\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}
因为我感兴趣的是,有没有更好的方法可以让实际值与预测值在中间对齐,并且距离相同。(我的解决方案是尝试并犯错误)
答案2
希望以下代码能够满足您的要求:
\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}
输出为:
答案3
\begin{tabular}{cc|c|c|}
&\multicolumn{1}{c}{}&\multicolumn{2}{c}{\textbf{Predicted}}\\
&\multicolumn{1}{c}{}&\multicolumn{1}{c}{}{\textbf{0}}
&\multicolumn{1}{c}{\textbf{1}}\\
\cline{3-4}
\multicolumn{1}{c}{\multirow{2}{*}{\rotatebox{90}{\textbf{True}}}}
&\textbf{0} &0.1 &0.3\\
\cline{3-4}
&\textbf{1} &0.5 &0.2\\
\cline{3-4}
\end{tabular}