Skip to content

Commit

Permalink
修正week3中误写成代码格式的数学公式,并对神经网络课后练习增加一张手绘图便于理解
Browse files Browse the repository at this point in the history
  • Loading branch information
Liam-Yang committed Apr 14, 2019
1 parent 36636b7 commit 7b20cdf
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 20 deletions.
4 changes: 2 additions & 2 deletions code/ex3-neural network/1- neural network.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@
"y_matrix = []\n",
"\n",
"for k in range(1, 11):\n",
" y_matrix.append((raw_y == k).astype(int))\n",
" y_matrix.append((raw_y == k).astype(int)) # 见配图 \"向量化标签.png\"\n",
"\n",
"# last one is k==10, it's digit 0, bring it to the first position,最后一列k=10,都是0,把最后一列放到第一列\n",
"y_matrix = [y_matrix[-1]] + y_matrix[:-1]\n",
Expand Down Expand Up @@ -877,7 +877,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.6.1"
"version": "3.7.0"
}
},
"nbformat": 4,
Expand Down
Binary file added code/ex3-neural network/向量化标签.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
38 changes: 20 additions & 18 deletions markdown/week3.md
Original file line number Diff line number Diff line change
Expand Up @@ -490,17 +490,19 @@ ${h_\theta}\left( x \right)={\theta_{0}}+{\theta_{1}}{x_{1}}+{\theta_{2}}{x_{2}^

$J\left( \theta \right)=\frac{1}{2m}\sum\limits_{i=1}^{m}{[({{({h_\theta}({{x}^{(i)}})-{{y}^{(i)}})}^{2}}+\lambda \sum\limits_{j=1}^{n}{\theta _{j}^{2}})]}$

如果我们要使用梯度下降法令这个代价函数最小化,因为我们未对$\theta_0$进行正则化,所以梯度下降算法将分两种情形:
如果我们要使用梯度下降法令这个代价函数最小化,因为我们未对$\theta_0$进行正则化,所以梯度下降算法将分两种情形:

$Repeat$ $until$ $convergence${

${\theta_0}:={\theta_0}-a\frac{1}{m}\sum\limits_{i=1}^{m}{(({h_\theta}({{x}^{(i)}})-{{y}^{(i)}})x_{0}^{(i)}})$

${\theta_j}:={\theta_j}-a[\frac{1}{m}\sum\limits_{i=1}^{m}{(({h_\theta}({{x}^{(i)}})-{{y}^{(i)}})x_{j}^{\left( i \right)}}+\frac{\lambda }{m}{\theta_j}]$

$for$ $j=1,2,...n$

}
​ ${\theta_0}:={\theta_0}-a\frac{1}{m}\sum\limits_{i=1}^{m}{(({h_\theta}({{x}^{(i)}})-{{y}^{(i)}})x_{0}^{(i)}})$

​ ${\theta_j}:={\theta_j}-a[\frac{1}{m}\sum\limits_{i=1}^{m}{(({h_\theta}({{x}^{(i)}})-{{y}^{(i)}})x_{j}^{\left( i \right)}}+\frac{\lambda }{m}{\theta_j}]$

​ $for$ $j=1,2,...n$

​ }




对上面的算法中$ j=1,2,...,n$ 时的更新式子进行调整可得:
Expand Down Expand Up @@ -545,19 +547,19 @@ def costReg(theta, X, y, learningRate):

$Repeat$ $until$ $convergence${

${\theta_0}:={\theta_0}-a\frac{1}{m}\sum\limits_{i=1}^{m}{(({h_\theta}({{x}^{(i)}})-{{y}^{(i)}})x_{0}^{(i)}})$
${\theta_j}:={\theta_j}-a[\frac{1}{m}\sum\limits_{i=1}^{m}{({h_\theta}({{x}^{(i)}})-{{y}^{(i)}})x_{j}^{\left( i \right)}}+\frac{\lambda }{m}{\theta_j}]$
$for$ $j=1,2,...n$
}
${\theta_0}:={\theta_0}-a\frac{1}{m}\sum\limits_{i=1}^{m}{(({h_\theta}({{x}^{(i)}})-{{y}^{(i)}})x_{0}^{(i)}})$

${\theta_j}:={\theta_j}-a[\frac{1}{m}\sum\limits_{i=1}^{m}{({h_\theta}({{x}^{(i)}})-{{y}^{(i)}})x_{j}^{\left( i \right)}}+\frac{\lambda }{m}{\theta_j}]$

$for$ $j=1,2,...n$

}

注:看上去同线性回归一样,但是知道 ${h_\theta}\left( x \right)=g\left( {\theta^T}X \right)$,所以与线性回归不同。
**Octave** 中,我们依旧可以用 `fminuc` 函数来求解代价函数最小化的参数,值得注意的是参数${\theta_{0}}$的更新规则与其他情况不同。
注:看上去同线性回归一样,但是知道 ${h_\theta}\left( x \right)=g\left( {\theta^T}X \right)$,所以与线性回归不同。
**Octave** 中,我们依旧可以用 `fminuc` 函数来求解代价函数最小化的参数,值得注意的是参数${\theta_{0}}$的更新规则与其他情况不同。
注意:

1. 虽然正则化的逻辑回归中的梯度下降和正则化的线性回归中的表达式看起来一样,但由于两者的${h_\theta}\left( x \right)$不同所以还是有很大差别。
1. 虽然正则化的逻辑回归中的梯度下降和正则化的线性回归中的表达式看起来一样,但由于两者的${h_\theta}\left( x \right)$不同所以还是有很大差别。

2. ${\theta_{0}}$不参与其中的任何一个正则化。

Expand Down

0 comments on commit 7b20cdf

Please sign in to comment.