使用 TikZ 或表格的 k 倍交叉验证图

使用 TikZ 或表格的 k 倍交叉验证图

我想知道如何使用表格或 TikZ 创建图形来描述交叉验证背后的想法。有人能帮我创建一些类似于附图的东西吗?

k倍交叉验证

答案1

无Ti版本Z 且仅tabular

\documentclass[]{article}

\usepackage[table]{xcolor}
\definecolor{ccellcolor}{HTML}{d09000}

\newcommand*\revealcline{\noalign{\vskip\arrayrulewidth}}
\newcommand*\nextrow[1]
  {\\\cline{#1}\noalign{\vskip1ex}\cline{#1}\revealcline}
\newcount\ccellA
\newcommand*\ccell[2]
  {%
    \def\tmpa{}%
    \ccellA=1
    \loop
      \ifnum#1=\ccellA
        \edef\tmpa{\unexpanded\expandafter{\tmpa\cellcolor{ccellcolor}}}%
      \fi
    \ifnum#2>\ccellA
      \advance\ccellA1
      \edef\tmpa{\unexpanded\expandafter{\tmpa&}}%
    \repeat
    \tmpa
  }

\begin{document}
\begin{tabular}[c]{l *5{|p{2em}}|}
  & \multicolumn{5}{c|}{$\longleftarrow$ Total Number of Dataset $\longrightarrow$}\\
  \cline{2-6}\revealcline
  Experiment 1 & \ccell{1}{5}
  \nextrow{2-6}
  Experiment 2 & \ccell{2}{5}
  \nextrow{2-6}
  Experiment 3 & \ccell{3}{5}
  \nextrow{2-6}
  Experiment 4 & \ccell{4}{5}
  \nextrow{2-6}
  Experiment 5 & \ccell{5}{5}\\
  \cline{2-6}
\end{tabular}\hskip1em
\begin{tabular}[c]{|p{2em}|l}
  \cline{1-1}
  \ccell{0}{1}  & Training
  \nextrow{1-1}
  \ccell{1}{1}  & Validation\\
  \cline{1-1}
\end{tabular}
\end{document}

在此处输入图片描述

答案2

今天是 5 月 1,所以我不用上班,我会为你画的;)

\documentclass[tikz,border=7pt]{standalone}
\usetikzlibrary{matrix}
\begin{document}
  \begin{tikzpicture}
    \matrix (M) [matrix of nodes,
        nodes={minimum height = 7mm, minimum width = 2cm, outer sep=0, anchor=center, draw},
        column 1/.style={nodes={draw=none}, minimum width = 4cm},
        row sep=1mm, column sep=-\pgflinewidth, nodes in empty cells,
        e/.style={fill=yellow!10}
      ]
      {
        Experiment 1 & |[e]| & & & & \\
        Experiment 2 & & |[e]| & & & \\
        Experiment 3 & & & |[e]| & & \\
        Experiment 4 & & & & |[e]| & \\
        Experiment 5 & & & & & |[e]| \\
      };
      \draw (M-1-2.north west) ++(0,2mm) coordinate (LT) edge[|<->|, >= latex] node[above]{Total number of datasets} (LT-|M-1-6.north east);
  \end{tikzpicture}
\end{document}

在此处输入图片描述

相关内容