我想要一个 k 倍交叉验证子样本的图表。我浏览了有关交叉验证的帖子,发现有 2 篇帖子可以帮助我构建交叉验证使用 TikZ 或表格的 k 倍交叉验证图和尝试绘制交叉验证。
我希望得到如下的子样本图:
\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}
我怎样才能获得更优雅的身材?
答案1
我block
在最后的中定义了一种新样式scope
,使用\node
s来绘制带有标签的矩形,并使用节点名称来绘制连接线。
\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}