预测函数
\[ f_\theta(x) = \theta_0 + \theta_1x + \theta_2x^2 \]
\[ X\cdot\theta = \begin{bmatrix} 1&x^{(1)}&x^{(1)^2}\\ 1&x^{(2)}&x^{(2)^2}\\ 1&x^{(3)}&x^{(3)^2}\\ \vdots&\vdots&\vdots\\ 1&x^{(n)}&x^{(n)^2} \end{bmatrix} \cdot \begin{bmatrix} \theta_0\\ \theta_1\\ \theta_2 \end{bmatrix} = \begin{bmatrix} \theta_0+\theta_1x^{(1)}+\theta_2x^{(1)^2}\\ \theta_0+\theta_1x^{(2)}+\theta_2x^{(2)^2}\\ \vdots\\ \theta_0+\theta_1x^{(n)}+\theta_2x^{(n)^2} \end{bmatrix} \]
更新表达式
\[ \theta_j := \theta_j - \eta\sum_{i=1}^n(f_\theta(x^{(i)}) - y^{(i)})x_j^{(i)} \]
\[ f = \begin{bmatrix} f_\theta(x^{(1)}) - y^{(1)}\\ f_\theta(x^{(2)}) - y^{(2)}\\ \vdots\\ f_\theta(x^{(n)}) - y^{(n)} \end{bmatrix} \]
\[ X = \begin{bmatrix}x0&x1&x2\end{bmatrix} = \begin{bmatrix} 1&x^{(1)}&x^{(1)^2}\\ 1&x^{(2)}&x^{(2)^2}\\ 1&x^{(3)}&x^{(3)^2}\\ \vdots&\vdots&\vdots\\ 1&x^{(n)}&x^{(n)^2} \end{bmatrix} \]
\[ \sum_{i=1}^n(f_\theta(x^{(i)}) - y^{(i)})x_j^{(i)} = f^TX \]
代码示例
1 | import numpy as np |