正则化——线性回归
線性回歸的代價函數正則化后為
\[J\left( \theta? \right){\rm{ = }}\frac{{\rm{1}}}{{{\rm{2}}m}}\left[ {\sum\limits_{i = 1}^m {{{\left( {{h_\theta }\left( {{x^{\left( i \right)}}} \right) - {y^{\left( i \right)}}} \right)}^2}}? + \lambda \sum\limits_{j = 1}^n {\theta _j^2} } \right]\]
此時梯度下降算法
重復{
\[{\theta _0}: = {\theta _0} - \alpha \left[ {\frac{1}{m}\sum\limits_{i = 1}^m {\left( {{h_\theta }\left( {{x^{\left( i \right)}}} \right) - {y^{\left( i \right)}}} \right)x_0^{\left( i \right)}} } \right]\]
\[{\theta _j}: = {\theta _j} - \alpha \left[ {\frac{1}{m}\sum\limits_{i = 1}^m {\left( {{h_\theta }\left( {{x^{\left( i \right)}}} \right) - {y^{\left( i \right)}}} \right)x_j^{\left( i \right)} + \frac{\lambda }{m}{\theta _j}} } \right]\left( {j = 1,2,...,n} \right)\]
}
此時normal equation為
\[\theta = {\left( {{X^T}X + \lambda \left[ {\begin{array}{*{20}{c}}
0&0&0&0\\
0&1&0&0\\
.&.&.&.\\
0&0&0&1
\end{array}} \right]} \right)^{ - 1}}{X^T}y\]
可以證明,正則化后括號里面的矩陣是可逆的
轉載于:https://www.cnblogs.com/qkloveslife/p/9866375.html
總結
- 上一篇: python入门之前面内容拾遗
- 下一篇: lintcode-828. 字模式