重建以下偏差-方差图

重建以下偏差-方差图

如果有人更熟悉 TiZ 包可以在 LaTeX 中复制以下图片:

有问题的图片http://zhangjunhd.github.io/assets/2014-10-01-bias-variance-tradeoff/1.png

设计不一定要相同。我对传达类似上述信息的图像更感兴趣。我自己无法在 LaTeX 中重建它,只能在 Word 中重建,但结果不太美观,我无法达到我想要的分辨率。

答案1

你可以从这个开始

\documentclass{article}
\usepackage{tikz}


\begin{document}

\begin{tikzpicture}
    \foreach \r/\col in {2.8 cm/white,2 cm/blue!50!white,1.2 cm/white,0.4 cm/red!50!white}{%
    \path[draw,fill=\col] (0,0) circle (\r) ;}

    \foreach \coords in {(0,.4),(.2,.5),(.1,.6),(-.2,.5)}{%
    \draw[fill=blue] \coords circle (.6mm);}

\end{tikzpicture}

\end{document}

在此处输入图片描述

答案2

版本元帖子luamplib,改编自我对类似问题只需改变用于目标和命中的图像即可。

用 编译lualatex

在此处输入图片描述

\documentclass[border=5mm]{standalone}
\usepackage{fontspec}
\setmainfont{Tex Gyre Pagella}
\usepackage{luamplib}
\begin{document}
\mplibtextextlabel{enable}
\begin{mplibcode}
beginfig(1);
numeric s;
picture target, hit;
s = 24;
target = image(for r=4 downto 1: 
  fill fullcircle scaled (r*s) withcolor if r=3: (.6,.7,.8) elseif r=1: (.6,.3,.3) else: white fi;
  draw fullcircle scaled (r*s); 
endfor);
hit  = image(fill fullcircle scaled 3 withcolor .8 blue; 
             draw fullcircle scaled 3;);
picture A, B, C, D;
A = target shifted (-2.25s,+2.25s);
B = target shifted (+2.25s,+2.25s);
C = target shifted (-2.25s,-2.25s);
D = target shifted (+2.25s,-2.25s);

% mark "n" hits centered at "p" with "r" degree of scattering
vardef mark_hits(expr n, p, r) = 
  for i=1 upto n:
     draw hit shifted p shifted (r * normaldeviate, r * normaldeviate);
  endfor
enddef;

draw A; mark_hits(12, center A, 3); 
draw B; mark_hits(12, center B, 12);
draw C; mark_hits(12, center C shifted (-s/2,s/2), 3);
draw D; mark_hits(12, center D shifted (s/2,-s/2),12);

label.top("\strut Low Variance",  1/2[ulcorner A, urcorner A]);
label.top("\strut High Variance", 1/2[ulcorner B, urcorner B]);
label.lft(textext("\strut Low Bias")  rotated 90, 1/2[llcorner A, ulcorner A] shifted 12 left);
label.lft(textext("\strut High Bias") rotated 90, 1/2[llcorner C, ulcorner C] shifted 12 left);

endfig;
\end{mplibcode}
\end{document}

答案3

PSTricks 解决方案:

\documentclass{article}

\usepackage{pstricks-add}
\psset{unit = 3}

\def\target(#1,#2){%
 {\psset{fillstyle = solid}
  \rput(#1,#2){%
    \pscircle[fillcolor = white](0.7,0.7){0.7}
    \pscircle[fillcolor = blue!60](0.7,0.7){0.5}
    \pscircle[fillcolor = white](0.7,0.7){0.3}
    \pscircle[fillcolor = red!80](0.7,0.7){0.1}}}}
\def\dots[#1](#2,#3){%
    \psRandom[
      dotsize = 2pt,
      randomPoints = 25
    ](!#2 #1 0.04 sub sub #3 #1 0.04 sub sub)%
     (!#2 #1 0.04 sub add #3 #1 0.04 sub add)%
     {\pscircle[linestyle = none](#2,#3){#1}}}

\begin{document}

\begin{pspicture}(3.45,3.45)
  \target(0.25,0)
  \target(2.05,0)
  \target(0.25,1.8)
  \target(2.05,1.8)
  \dots[0.12](0.95,1.1)
  \dots[0.1](0.92,2.53)
  \dots[0.3](2.5,1.15)
  \dots[0.3](2.7,2.5)
  \rput{90}(0.05,0.7){High Bias}
  \rput{90}(0.05,2.5){Low Bias}
  \rput(0.95,3.4){Low Variance}
  \rput(2.75,3.4){High Variance}
\end{pspicture}

\end{document}

输出

这些点将随机放置在剪切路径内(此处,每个目标内有一个圆圈)。

请注意,您可能需要编译几次以确保点不会进入剪辑区域的边界。

相关内容