哲哲的ML筆記(一到九小結)

一到九部分學習的主要內容是線性模型與代價函數
J(\theta)=\dfrac{1}{2m}\sum\limits_{i=1}^{m}(h_\theta( x^i)-y^i)^2
但通常處理數據時不是單獨一個樣本,而是將所有樣本及其特徵存儲到矩陣中
比如樣本矩陣X存儲城市的人口
\begin{equation} X = \left[ \begin{array}{ccc} 6 \\ 5 \\ 8 \\ … \end{array} \right] \end{equation}
y存儲一輛食物卡車一天的利潤
\begin{equation} y = \left[ \begin{array}{ccc} 17 \\ 9 \\ 13 \\ … \end{array} \right] \end{equation}
參數\theta矩陣爲
\begin{equation} \theta = \left[ \begin{array}{ccc} \theta_0 \\ \theta_1 \end{array} \right] \end{equation}

X矩陣新增一列1,原因參照(九:正規方程)
\begin{equation} X = \left[ \begin{array}{ccc} 1& 6 \\ 1& 5 \\ 1&8 \\ … \end{array} \right] \end{equation}

此時J(\theta)=\dfrac{1}{2m}(X\theta-y)^2=\dfrac{1}{2m}(X\theta-y)'(X\theta-y)
\theta_j=\theta_j-\alpha\frac{\partial}{\partial \theta_j} J(\theta),可得
\theta=\theta-\alpha\frac{\partial}{\partial \theta} J(\theta)=\theta-\dfrac{\alpha}{m}X'(X\theta-y)

其中梯度是\dfrac{1}{m}X'(X\theta-y)維數是(n+1)m m(n+1) (n+1)*1=n+1,即樣本的特徵數+1

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章