線性回歸閉式解推導


單詞:

multivariate linear regression  多元線性回歸

Here I want to show how the normal equation is derived. 此處是如何獲得該等式。

Given the hypothesis function. 給出假設函數。 [haɪˈpɒθəsɪs]

 

多元線性回歸應用舉例:

幸福度預測:有身體、財富、學歷等等自變量因素,有幸福度因變量因素,有一些樣本數據,希望得到一個從這些自變量到幸福度這個因變量的映射函數。

 

解析過程:

回歸函數:

\begin{equation}
h_{\theta}(x)=\theta_{0} x_{0}+\theta_{1} x_{1}+\cdots+\theta_{n} x_{n}
\end{equation}

最小化平方差損失:

\begin{equation}
J\left(\theta_{0 \ldots n}\right)=\frac{1}{2 m} \sum_{i=1}^{m}\left(h_{\theta}\left(x^{(i)}\right)-y^{(i)}\right)^{2}
\end{equation}

此處的$x^{(i)}$和$y^{(i)}$是第i個樣本數據。

我們需要學習的參數$\theta$可以,可以視為一個列向量:

\begin{equation}
\left( \begin{array}{c}{\theta_{0}} \\ {\theta_{1}} \\ {\dots} \\ {\theta_{n}}\end{array}\right)
\end{equation}

這樣回歸函數就是:$h_{\theta}(x)=x{\theta}$ 。${x}$是行向量形式。

 對於求和運算,實際上也可以變換成矩陣相乘的形式。上面的最小平方差損失,可以變換為:

\begin{equation}
J(\theta)=\frac{1}{2 m}(X \theta-y)^{T}(X \theta-y)
\end{equation}

這個地方的$X$是$m$行,$n$列的,$m$是樣本數目,$n$是樣本中的變量數目。$y$是一個列向量。

不去考慮前面的$\frac{1}{2 m}$這個系數。利用線性代數的知識將括號去掉:

\begin{equation}
\begin{array}{c}{J(\theta)=\left((X \theta)^{T}-y^{T}\right)(X \theta-y)} \\ {J(\theta)=(X \theta)^{T} X \theta-(X \theta)^{T} y-y^{T}(X \theta)+y^{T} y}\end{array}
\end{equation}

注意到:$X \theta$實際上一個列向量,$y$也是一個列向量,那么$(X \theta)^{T} y$和$y^{T}(X \theta)$是相等的。上式可以簡化為:

\begin{equation}
J(\theta)=\theta^{T} X^{T} X \theta-2(X \theta)^{T} y+y^{T} y
\end{equation}

此處的$\theta$是未知數,可以對其求取偏微分運算,但是$\theta$是一個向量,這就涉及到向量求導了。

\begin{equation}
\frac{\partial J}{\partial \theta}=2 X^{T} X \theta-2 X^{T} y=0
\end{equation}

\begin{equation}
X^{T} X \theta=X^{T} y
\end{equation}

\begin{equation}
\theta=\left(X^{T} X\right)^{-1} X^{T} y
\end{equation}


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM