2

I want to have a figure of having a subsample from k-fold cross-validation. I have gone through the post regarding cross-validation and I have found 2 post that can help me construct the cross-validation in k-Fold cross-validation figure using TikZ or table and Trying to plot cross validation.

I hope to have the figure of sub sample as below:

subsample from fold

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{arrows.meta, positioning}
  \begin{tikzpicture}[node distance=0mm,minimum height=1cm,outer sep=3mm,scale=0.7,>=Latex,font=\footnotesize,
 indication/.style={minimum height=0cm,outer sep=0mm},
  oneblock/.style={transform shape,minimum width=1cm,draw},
  fullset/.style={transform shape,minimum width=10cm,draw}]
% left part of picture
\node[fullset,anchor=west] at (0,0) (A) {};
\node[above=of A.north,indication] (ATXT) {TRAINING SET};
\node[oneblock,minimum width=2cm,anchor=west,right=of A,fill=lightgray,outer sep=0mm] (A1) {};
\path (ATXT) -| (A1) node[midway] {TEST SET};
\node[fullset,anchor=west] at (0,-4) (B) {};
\foreach \x in {0,1,...,9}
{
    \draw (B.west) +(\x,0) node[oneblock,anchor=west,draw] {};
}
\draw[->] (A) -- (B) node[midway,fill=white,indication] {divide into 10 folds of equal size};

% right part of picture
\begin{scope}[xshift=15cm,scale=0.5,local bounding box=rightside box]
\foreach \x in {0,1}
{
    \foreach \y in {0,1,...,4}
    {
        \draw (\x*11,0) +(0,-\y*2) node[fullset,anchor=west] {};
        \draw (\x*11,0) +(\x*5+\y,-\y*2) node[oneblock,draw,anchor=west,fill=lightgray] {};
    }
}
%node
\draw[color=red!60,very thick](1,0) circle (1.2);
%line
\draw[black, thick] (0.7,0) -- (0.7,3);
 \draw[black, thick] (0.7,0) -- (3,3);
  \draw[blue, very thick] (0.8,3.1) rectangle (3,5);
 \draw[blue, very thick] (3.2,3.2) rectangle (5,5);
\coordinate (R) at (rightside box.west);
\end{scope}

% connecting arrow
\draw[->] (B.east) -- +(2.5,0) node[below,align=center,indication] {run experiments\\using 10 different\\partitionings} |- (R);
\end{tikzpicture}

This is what i obtained enter image description here

how can i get a more elegent figure?

1
  • 2
    Please make your code compilable in the form of a MWE (I have retracted my close vote and -1) Jul 29 '19 at 10:48
2

I defined a new style block in the final scope, used \nodes to draw the rectangles with labels, and used the node names to draw the connecting lines.

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{arrows.meta, positioning}
\begin{document}
\begin{tikzpicture}[node distance=0mm,minimum height=1cm,outer sep=3mm,scale=0.7,>=Latex,font=\footnotesize,
 indication/.style={minimum height=0cm,outer sep=0mm},
  oneblock/.style={transform shape,minimum width=1cm,draw},
  fullset/.style={transform shape,minimum width=10cm,draw}]
% left part of picture
\node[fullset,anchor=west] at (0,0) (A) {};
\node[above=of A.north,indication] (ATXT) {TRAINING SET};
\node[oneblock,minimum width=2cm,anchor=west,right=of A,fill=lightgray,outer sep=0mm] (A1) {};
\path (ATXT) -| (A1) node[midway] {TEST SET};
\node[fullset,anchor=west] at (0,-4) (B) {};
\foreach \x in {0,1,...,9}
{
    \draw (B.west) +(\x,0) node[oneblock,anchor=west,draw] {};
}
\draw[->] (A) -- (B) node[midway,fill=white,indication] {divide into 10 folds of equal size};

% right part of picture
\begin{scope}[
  xshift=15cm,
  scale=0.5,
  local bounding box=rightside box,
  block/.style={minimum height=0mm,outer sep=0, draw, inner sep=2mm} % <--- new
]
\foreach \x in {0,1}
{
    \foreach \y in {0,1,...,4}
    {
        \draw (\x*11,0) +(0,-\y*2) node[fullset,anchor=west] {};
        \draw (\x*11,0) +(\x*5+\y,-\y*2) node[oneblock,draw,anchor=west,fill=lightgray] {};
    }
}
%the next six lines are new
\coordinate (pointofinterest) at (1,0);
\draw[color=red!60,very thick] (pointofinterest) circle (1.2);

\node [above right=5mm and 5mm of pointofinterest, name=70, block] {70\%};
\node [right=1cm of 70, name=30, block] {30\%};

\draw (pointofinterest) -- (70);
\draw (pointofinterest) -- (30);


\coordinate (R) at (rightside box.west);
\end{scope}

% connecting arrow
\draw[->] (B.east) -- +(2.5,0) node[below,align=center,indication] {run experiments\\using 10 different\\partitionings} |- (R);
\end{tikzpicture}

\end{document}
1
  • thank you @Torbjørn T. as expected.
    – Norin
    Jul 29 '19 at 14:28

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.