在 tikz 中绘制偏差/方差/误差权衡

在 tikz 中绘制偏差/方差/误差权衡

我正在尝试在 LaTeX/tikz 中创建以下图形。我能够绘制凸“总误差”线,但似乎无法完成图形。我想展示机器学习模型中的偏差/方差权衡。

任何朝着正确方向的帮助/推动都将受到赞赏。

我怎样才能复制以下情节?

在此处输入图片描述

答案1

像这样。

在此处输入图片描述

% Adapted from https://raw.githubusercontent.com/MartinThoma/LaTeX-examples/master/tikz/bias-variance/bias-variance.tex
\documentclass[border=2pt]{standalone}
\usepackage[dvipsnames]{xcolor}
\usepackage{pgfplots}
\usepackage{sansmath}
\usetikzlibrary{arrows.meta,bending}
\tikzset{>=stealth,
OptimumStyle/.style={align=center,anchor=east,rotate=90,font=\sffamily\scriptsize}
}
\pgfplotsset{compat=1.17,
samples=101,
axis lines = left,
every axis plot/.append style={line width=2pt},
}

\begin{document}
\begin{tikzpicture}[font=\sffamily\sansmath]
    \begin{axis}[
        xmin= 0,     
        xmax= 2,    
        ymin= 0,     
        ymax= 2,   
        xlabel=Model Complexity,
        ylabel=Error,
        ticks=none,
        xticklabels={\empty},
        yticklabels={\empty}
    ]
      \addplot[domain=0.2:1.9,Maroon,<->] {1/(x+0.3)-0.2};   %Bias
      \addplot[domain=0.2:1.9,TealBlue,<->] {0.12*e^(1.40*x)};   %Variance
      \addplot[domain=0.39:1.61,black,<->] {3*(x-2)*x+3.8};  %Total error
      \addplot[dotted,thin] coordinates {(1,0) (1,2)};       %Optimum model complexity
      \node[OptimumStyle] at (axis cs:0.9,2) {Optimum Model\\Complexity};
      \node[anchor=south west,text=Maroon] at (axis cs:1.4,0.4){Bias\textsuperscript{2}};
      \node[anchor=north west,text=TealBlue] at (axis cs:1.4,0.85){Variance};
      \node[anchor=south east,align=center] at (axis cs:1.5,1.5){Total\\error};
      \legend{}
    \end{axis}
\end{tikzpicture}
\end{document}

相关内容