> For the complete documentation index, see [llms.txt](https://windmising.gitbook.io/liu-yu-bo-play-with-machine-learning/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://windmising.gitbook.io/liu-yu-bo-play-with-machine-learning/src/chapter9-2/9-3.md).

# 9-3 逻辑回归算法损失函数的梯度

![](http://windmissing.github.io/images/2019/162.jpg)

线性回归算法的梯度： ![](http://windmissing.github.io/images/2019/163.jpg) 逻辑回归算法的梯度：

$$
\nabla J(\theta) = \frac{1}{m} \cdot \
\begin{Bmatrix}
\sum\_{i=1}^m (\hat y^{(i)}-y^{(i)}) \\
\sum\_{i=1}^m (\hat y^{(i)}-y^{(i)})\cdot X\_1^{(i)} \\
\sum\_{i=1}^m (\hat y^{(i)}-y^{(i)})\cdot X\_2^{(i)} \\
... \\
\sum\_{i=1}^m (\hat y^{(i)}-y^{(i)})\cdot X\_n^{(i)} \\
\end{Bmatrix}   \
\= \frac{1}{m}\cdot X\_b^T\cdot (\sigma(X\_b\theta)-y)
$$
