我有一张长桌子,
但是 overleaf 中有错误的信息!
额外的对齐标签已更改为 \cr。
我不知道该如何解决这个问题?
这是我的代码
\begin{table}[ht]
\caption{Comparison of the model for the Accuracy using different supervised machine learning algorithms with 3 types of Features selection: ANOVA, Chi-squared and No features selection.}
\centering
\begin{adjustbox}{width=\textwidth}
\begin{tabular}{c|cccc} %
%\toprule
\hline
& & & & \\
\multirow{2}{*}{Machine Learning Methods} & \multicolumn{4}{c}{\centering Features Selection : Anova} &
\cmidrule{2-5} %\cmidrule{2-5}
%\parbox[c]{.45\linewidth}{\centering { ML Method }}}
& {\centering Number of Features} & {Accuracy} & {Number of Features} & {Accuracy} \\
\hline
%\midrule
& & & & \\
LR & \multirow{5}{*}{\rotatebox[origin=c]{90}{5000 features}} & 100\% & \multirow{5}{*}{\rotatebox[origin=c]{90}{7000 features}} & 100\% \\
% & & & & \\
SVM & & 100\% & & 100\% \\
% & & & & \\
XGBoost & & 100\% & & 100\% \\
% & & & & \\
RF & &100\% & & 100\% \\
% & & & & \\
Perceptron & & 100\% & & 100\% \\
& & & & \\
\hline %\hline
& & & & \\
\multirow{2}{*}{Machine Learning Methods} & \multicolumn{4}{c}{\centering Features Selection : Chi-squared} &
\cmidrule{2-5} %\cmidrule{2-5}
%\parbox[c]{.45\linewidth}{\centering { ML Method }}}
& {\centering Number of Features} & {Accuracy} & {Number of Features} & {Accuracy} \\
\hline
%\midrule
& & & & \\
LR & \multirow{5}{*}{\rotatebox[origin=c]{90}{5000 features}} & 98.68\% & \multirow{5}{*}{\rotatebox[origin=c]{90}{7000 features}} & 98.68\% \\
%& & & & \\
SVM & & 100\% & & 100\% \\
%& & & & \\
XGBoost & & 100\% & & 100\% \\
%& & & & \\
RF & &100\% & & 100\% \\
%& & & & \\
Perceptron & & 100\% & & 100\% \\
& & & & \\
\hline %\hline
& & & & \\
\multirow{2}{*}{Machine Learning Methods} & \multicolumn{4}{c}{\centering No Features Selection} &
\cmidrule{2-5} %\cmidrule{2-5}
%\parbox[c]{.45\linewidth}{\centering { ML Method }}}
& & {Number of Features} & {Accuracy} & \\
\hline
%\midrule
& & & & \\
LR & &\multirow{5}{*}{\rotatebox[origin=c]{90}{ALL features}} & 71.05\% & \\
%& & & & \\
SVM & & & 100\% & \\
%& & & & \\
XGBoost & & & 100\% & \\
%& & & & \\
RF & & &100\% & \\
% & & & & \\
Perceptron & & & 100\% & \\
& & & & \\
\bottomrule
\end{tabular}
\end{adjustbox}
\end{table}
答案1
这个答案分为两部分。
第 1 部分:最小变化
不是最小的,但这是我能做到的最小的。这通过旋转表格来修复错误并消除缩放。它还使用方法booktabs
。如果您不想使用booktabs
,也可以,但不要尝试将其方法与垂直规则和\hline
s 混合使用。
\documentclass{article}
\usepackage{multirow,array}
\usepackage{booktabs}
\usepackage{rotating}
\begin{document}
\begin{sidewaystable}
\centering
\caption{Comparison of the model for the Accuracy using different supervised machine learning algorithms with 3 types of Features selection: ANOVA, Chi-squared and No features selection.}
\begin{tabular}{ccccc}
\toprule
\multirow{2}{*}{Machine Learning Methods} & \multicolumn{4}{c}{Features Selection : Anova} \\
\cmidrule(r){2-5}
& {Number of Features} & {Accuracy} & {Number of Features} & {Accuracy} \\
\midrule
LR & \multirow{5}{*}{\rotatebox[origin=c]{90}{5000 features}} & 100\% & \multirow{5}{*}{\rotatebox[origin=c]{90}{7000 features}} & 100\% \\
SVM & & 100\% & & 100\% \\
XGBoost & & 100\% & & 100\% \\
RF & &100\% & & 100\% \\
Perceptron & & 100\% & & 100\% \\
\cmidrule(lr){1-5}
\multirow{2}{*}{Machine Learning Methods} & \multicolumn{4}{c}{Features Selection : Chi-squared} \\
\cmidrule(r){2-5}
& Number of Features & {Accuracy} & {Number of Features} & {Accuracy} \\
\cmidrule(lr){1-5}
LR & \multirow{5}{*}{\rotatebox[origin=c]{90}{5000 features}} & 98.68\% & \multirow{5}{*}{\rotatebox[origin=c]{90}{7000 features}} & 98.68\% \\
SVM & & 100\% & & 100\% \\
XGBoost & & 100\% & & 100\% \\
RF & &100\% & & 100\% \\
Perceptron & & 100\% & & 100\% \\
\cmidrule(lr){1-5}
\multirow{2}{*}{Machine Learning Methods} & \multicolumn{4}{c}{No Features Selection} \\
\cmidrule(r){2-5}
& & {Number of Features} & {Accuracy} & \\
\cmidrule(lr){1-5}
LR & &\multirow{5}{*}{\rotatebox[origin=c]{90}{ALL features}} & 71.05\% & \\
SVM & & & 100\% & \\
XGBoost & & & 100\% & \\
RF & & &100\% & \\
Perceptron & & & 100\% & \\
\bottomrule
\end{tabular}
\end{sidewaystable}
\end{document}
结果不是很好,但是更好:
第 2 部分:重组内容
答案2
错误的根源在于您的 Anova 行(以及其他行)基本上如下:
col 1 & columns 2-5 & \cmidrule{2-5} col 6 & col 7 & col 8 & col 9 & col 10 \\
正如 cfr 评论的那样,您\\
之前想要的\cmidrule
是 ,而不是&
。但正如他们所指出的那样,不要将 booktabs 与 hlines 和垂直规则混合使用(booktabs 讨厌垂直规则,并定义了您应该使用的自己的水平规则)。
如果某项适用于表格的每一行,那么我建议将其从表格移到表格的标题或列标题中。这大大减少了表格的大小,使比较准确性变得更加容易。我们还可以\usepackage{siunitx}
获取其S
列类型。我最终得到:
\documentclass{article}
\usepackage{siunitx}
\usepackage{booktabs}
\begin{document}
\begin{table}
\centering
\caption{Percentage accuracy using different supervised machine learning methods with 3 types of features selection and differing numbers of features.}
\begin{tabular}{cSSSSS}\toprule
& \multicolumn{5}{c}{Feature selection and number of features} \\
Method & \multicolumn{2}{c}{ANOVA} & \multicolumn{2}{c}{Chi-squared} & {No Features} \\
& {5000} & {7000} & {5000} & {7000} & {all features} \\\midrule
LR & 100 & 100 & 98.68 & 98.68 & 71.05 \\
SVM & 100 & 100 & 100 & 100 & 71.05 \\
XGBoost & 78.95 & 77.63 & 82.89 & 82.89 & 68.42 \\
RF & 88.16 & 84.21 & 88.16 & 88.16 & 71.05 \\
Perceptron & 98.68 & 97.37 & 97.37 & 96.05 & 72.37 \\\bottomrule
\end{tabular}
\end{table}
\end{document}
(我对使用“所有特征”的“无特征选择”有点困惑,因此该列标题确实令人困惑。)
现在,我们已经将表格缩小到足够小,不需要旋转或调整其大小。并且准确度已收集到足够多的数据,因此我们可以一次性查看所有数据并进行有意义的比较。