What & How & Why

差别

这里会显示出您选择的修订版和当前版本之间的差别。

到此差别页面的链接

两侧同时换到之前的修订记录前一修订版
后一修订版
前一修订版
math:linear_algebra:matrix_engineers:week3 [2024/01/10 14:41] – [利用 normal equation 计算 best fit line] codingharemath:linear_algebra:matrix_engineers:week3 [2024/02/02 06:27] (当前版本) – [The Least-squares problem] codinghare
行 459: 行 459:
 \] \]
 很明显,这是一个 linear system。在这个 Linear system 中,$x$, $y$ 都是已知的,而 $\beta_0, \beta_1$ 是未知的。因此可以做下面的变型: 很明显,这是一个 linear system。在这个 Linear system 中,$x$, $y$ 都是已知的,而 $\beta_0, \beta_1$ 是未知的。因此可以做下面的变型:
 +\\ \\ 
 {{ :math:linear_algebra:matrix_engineers:least_problem_axb.svg?200 |}} {{ :math:linear_algebra:matrix_engineers:least_problem_axb.svg?200 |}}
 \\ \\  \\ \\ 
行 507: 行 508:
 标红的部分被称为 //Projection matrix//。该矩阵将 $b$ 投影到 $Col(A)$ 上。 标红的部分被称为 //Projection matrix//。该矩阵将 $b$ 投影到 $Col(A)$ 上。
 ==利用 normal equation 计算 best fit line== ==利用 normal equation 计算 best fit line==
-//假设有数据点:$(1,1), (2,3),(3,2)$,求过这几点的 best fit line。//+//假设有数据点:$(1,1), (2,3),(3,2)$,求过这几点的 best fit line。//\\ \\  
 +首先,根据数据点,以 $y = \beta_0 + \beta_1x$ 为模板,建立 linear system。通过 linear system 确定 $A$: 
 + 
 +\[ 
 + 
 +\begin{pmatrix} 
 +  1&1 \\ 
 +  1& 2\\ 
 +  1&3 
 +\end{pmatrix} 
 +\begin{pmatrix} 
 +\beta_0\\ 
 +\beta_1 
 + 
 +\end{pmatrix} 
 +
 +\begin{pmatrix} 
 + 1\\ 
 + 3\\ 
 +
 +\end{pmatrix} 
 +\] 
 +将 $A$ 带入 normal equation: 
 +\[ 
 +\begin{pmatrix*} 
 +  1&  1& 1\\ 
 +  1&  2&3 
 +\end{pmatrix*} 
 +\begin{pmatrix*} 
 +  1&1 \\ 
 +  1& 2\\ 
 +  1&3 
 +\end{pmatrix*} 
 +\begin{pmatrix*} 
 +\beta_0\\ 
 +\beta_1 
 + 
 +\end{pmatrix*} 
 +
 +\begin{pmatrix*} 
 +  1&  1& 1\\ 
 +  1&  2&3 
 +\end{pmatrix*} 
 +\begin{pmatrix*} 
 + 1\\ 
 + 3\\ 
 +
 +\end{pmatrix*} 
 +\] 
 +\\  
 +计算后得到关于 $\beta_0$ 和 $\beta_1$ 的 linear system。此时的未知数与等式数量相同,因此可以求解: 
 +\\  
 +\[ 
 +\begin{pmatrix*} 
 + 3 &6 \\ 
 + 6 &14 
 +\end{pmatrix*} 
 +\begin{pmatrix*} 
 +\beta_0\\ 
 +\beta_1 
 + 
 +\end{pmatrix*} 
 +
 +\begin{pmatrix*} 
 + 6\\ 
 +13 
 +\end{pmatrix*} 
 + 
 +\] 
 +\\ 解得 $\beta_0 = 1$,$\beta_1 = 1/2$,因此得到的直线方程为 $y = 1 + 1/2 * x$