AndrewNg Machine Learning 总结之Linear regression
Contents
Linear regression
线性回归模型:
$$
h_\theta(x)=\theta^Tx
$$
代价函数:
$$
J(\theta)={(1/2m)}{\sum_{i=1}^{m}{(h_\theta(x^{(i)})-y^{(i)})^2}}
$$
1 | function J = computeCost(X, y, theta) |
梯度下降法更新theta:
$$
\theta_j:=\theta_j-\alpha(1/m){\sum_{i=1}^{m}{(h_\theta(x^{(i)})-y^{(i)}){x_j^{(i)}}}}
$$
1 | function [theta, J_history] = gradientDescent(X, y, theta, alpha, num_iters) |
正规方程法直接得到theta解析解:
$$
\theta=(X^TX)^{-1}{X^T}y
$$
1 | function [theta] = normalEqn(X, y) |
特征归一化:
$$
x:=(x^i-mu)/s^i
$$
1 | function [X_norm, mu, sigma] = featureNormalize(X) |
Author: Zongpu
Link: http://yoursite.com/2019/08/06/AndrewNgMachineLearning%E6%80%BB%E7%BB%93%E4%B9%8BLinearRegression/
License: 知识共享署名-非商业性使用 4.0 国际许可协议