Modifying a structure
I consider only part you drawn in question (assuming that adding other is no problem to you):
\documentclass[tikz,border=3mm]{standalone}
\usetikzlibrary{decorations.pathreplacing,
calligraphy}
\begin{document}
\begin{tikzpicture}[
font = \sffamily,
BC/.style = {decorate,
decoration={calligraphic brace, amplitude=3pt,
pre =moveto, pre length=1pt,
post=moveto, post length=1pt,
raise=2pt, mirror},
thick,
pen colour=black
},
box/.style = {draw, semithick, fill=#1,
text width=5em, text depth=0.5ex, minimum height=4ex,
align=center, inner sep=0pt, outer sep=0pt},
box/.default= none
]
\foreach \x in {1,...,4}
\foreach \y in {1,...,4}
{
\ifnum\x=\y
\node (n\x\y) [box=cyan!30] at (\x*5em,{(3-\y)*4ex}) {Validation};
\else
\node (n\x\y) [box] at (\x*5em,{(3-\y)*4ex}) {Training};
\draw[BC] (n1\y.north west) -- node[left=5pt] {Fold \y} (n1\y.south west);
\fi
}
\draw[BC] (n41.north east)
-- node[above=5pt,align=left] {Data split into 4 partitions}
(n11.north west);
\foreach \i in {4,...,1}
\node (n4\i) [right] at (n4\i.east) {Validation score \# \i};
\draw[BC] (n44.south east) --
node[right=5pt,align=left] {Final\\ score\\ average} (n41.north east);
\end{tikzpicture}
\end{document}
Here is tan adaption that fills the matrix automatically.
\documentclass[tikz,border=3.14mm]{standalone}
\usetikzlibrary{matrix,decorations.pathreplacing}
\newcounter{Vali}
\begin{document}
\begin{tikzpicture}[font=\sffamily,
my cell/.style={minimum width=5em,text height=1.1em,text depth=0.3em,draw,anchor=center},
sdiag/.style={row #1 column #1/.style={nodes={my cell,node contents=Validation,fill=gray!10}}},
Vali/.style={/utils/exec=\stepcounter{Vali},my cell,draw=none,
node contents=Validation score \#\number\value{Vali}},
decoration=brace]
\matrix(mat) [matrix of nodes,nodes in empty cells,
nodes={my cell,node contents=Training},
sdiag/.list={1,...,4},
column 5/.style={every node/.style={Vali}},
column sep=-\pgflinewidth,row sep=-\pgflinewidth]
{ & & & & \\
& & & & \\
& & & & \\
& & & & \\
};
\foreach \X in {1,...,4}
{\draw[decorate] (mat.west|-mat-\X-1.south) -- (mat.west|-mat-\X-1.north)
node[midway,left]{Fold \X};}
\draw[decorate] (mat-1-1.west|-mat.north) -- (mat-1-4.east|-mat.north)
node[midway,above]{Data split in 4 partitions};
\draw[decorate] (mat.north east) -- (mat.south east)
node[midway,right,align=center]{Final score\\ average};
\end{tikzpicture}
\end{document}
You can automatize things even further. When the nodes in the matrix are created, their positions get stored in \pgfmatrixcurrentrow
and \pgfmatrixcurrentcolumn
. This can be used for \ifnum
statements.
\documentclass[tikz,border=3.14mm]{standalone}
\usetikzlibrary{matrix,decorations.pathreplacing}
\begin{document}
\begin{tikzpicture}[font=\sffamily,my cell/.style={
minimum width=5em,text height=1.1em,text
depth=0.3em,draw,anchor=center,
execute at begin node={
\ifnum\the\pgfmatrixcurrentcolumn=5
Validation score \#\the\pgfmatrixcurrentrow
\else
\ifnum\the\pgfmatrixcurrentrow=\the\pgfmatrixcurrentcolumn
Validation
\else
Training
\fi
\fi},
/utils/exec={\ifnum\the\pgfmatrixcurrentrow=\the\pgfmatrixcurrentcolumn\relax
\pgfkeysalso{/tikz/fill=gray!20}
\fi
\ifnum\the\pgfmatrixcurrentcolumn=5
\pgfkeysalso{draw=none}
\fi}
}, decoration=brace]
\matrix(mat) [matrix of nodes,nodes in empty cells,
nodes={my cell}, column sep=-\pgflinewidth,row sep=-\pgflinewidth]
{ & & & & \\
& & & & \\
& & & & \\
& & & & \\
};
\foreach \X in {1,...,4}
{\draw[decorate] (mat.west|-mat-\X-1.south) -- (mat.west|-mat-\X-1.north)
node[midway,left]{Fold \X};}
\draw[decorate] (mat-1-1.west|-mat.north) -- (mat-1-4.east|-mat.north)
node[midway,above]{Data split in 4 partitions};
\draw[decorate] (mat.north east) -- (mat.south east)
node[midway,right,align=center]{Final score\\ average};
\end{tikzpicture}
\end{document}