Coursera深度學習第一門課第二週
本週學習目標:
Build a logistic regression model, structured as a shallow neural network
Implement the main steps of an ML algorithm, including making predictions, derivative computation, and gradient descent.
Implement computationally efficient, highly vectorized, versions of models.
Understand how to compute derivatives for logistic regression, using a backpropagation mindset.
Become familiar with Python and Numpy
Work with iPython Notebooks
Be able to implement vectorization across multiple training examples
yhat即給定輸入特徵x時,預測y為1的概率,這裡我們使用sigmoid函式,當大於0時概率取值為0.5越大越接近1.
在分類問題中平方誤差無法讓梯度下降演算法良好執行,所以在邏輯迴歸中我們會選擇-(y*log^y+(1-y)
*log^(1-y))作為我們的誤差函式

關於梯度下降:梯度是我們沿著上升率最快的地方,那麼負的梯度即是下降最快的,我們要到一個區域性最低點那麼w = w - alha*dw

sigmoid函式影象
實現sigmoid,
import numpy as np
def sigmoid(x):
s = 1./(1.+np.exp(-x))
return s
然後計算s的梯度
def sigmoid_derivative(x):
s = sigmoid(x)
ds = s*(1-s)
return ds
重要知識:我們通常需要正規化將各個元素,這樣我們的梯度下降演算法將會更好的執行.
x_norm = np.linalg.norm(x,axis=1,keepdims=True)按行進行相加得出平方和的開方
如果進行多分類的話就需要用的softmax函數了

如果過擬合了我們可以要對他進行L1和L2約束


我們建立演算法一般步驟是:
1.定義模型結構
2.初始化模型引數
3.開始迴圈計算
計算當前損失函式(前向傳播)
計算當前梯度(反向傳播)
更新引數(梯度下降)