我正在上概率和统计课程,我想画一个逻辑回归图,所以我想我会用 LaTeX 来做这个。这是我第一次使用它,所以我遇到了一些麻烦。我希望我的图表看起来像这样(见图 1),但我得到的输出却像这样(见图 2)。我已经定义了 S 型函数和域,但看起来有点乱。有人能很好地解决这个问题吗?这是我的代码:
\documentclass{article}
\usepackage[utf8]{inputenc} % Required for inserting images
\usepackage{pgfplots}
\pgfplotsset{compat=1.18, width=10cm}
\begin{document}
\pgfplotsset{width=9cm,compat=newest}
\begin{figure}[ht]
\begin{tikzpicture}
\begin{axis}[
scale only axis,
inner axis line style={->},
xlabel={$x$ Household's income [KSEK]},
ylabel={$y$ Probability of purchasing a car},
ytick={0,0.5,...,1},
xtick={0,10,...,60},
ymin=0,
ymax=1,
xmin=0,
xmax=60,
]
\addplot[color=black, thick, mark=*] coordinates {
(5, 0.02)
(8, 0.02)
(11, 0.02)
(15, 0.02)
(17, 0.02)
(22, 0.02)
(24, 0.02)
(34, 0.02)
};
\addplot[color=black, thick, mark=*] coordinates {
(24, 0.98)
(33, 0.98)
(37, 0.98)
(45, 0.98)
(47, 0.98)
(50, 0.98)
(52, 0.98)
(55, 0.98)
};
\addplot[color=black] coordinates {
(0, 0.5)
(60, 0.5)
};
\addplot [domain=0.5:59.5, samples=100,
thick, color=black] {1/(1+exp(-x)};
\end{axis}
\end{tikzpicture}
\end{figure}
\end{document}