【Stanford Machine Learning Open Course】6. week2编程题解
这里是斯坦福大学机器学习网络课程的学习笔记。课程地址是:https://class.coursera.org/ml-2012-002/lecture/index
题目包括计算成本函数,下降梯度, 正规方程组,特征归一化
%1/7 warm up:
A=eye(5)
%2/7, 5/7 compute cost function (for one or multi variables)
J=1/(2*m)*sum((X*theta-y).^2);
%3/7, 6/7Gradient Descent (for one or multi variables)
theta = theta-alpha/m*((X*theta-y)'*X)';
%4/7 Feature Normalization
mu=mean(X);
sigma=std(X);
X_norm = X - ones(size(X)*diag(mu)) ./ (ones(size(X)*diag(sigma))
%7/7 Normal Equation
theta=pinv(X'*X)*X'*y;
转载请注明出处: http://www.cnblogs.com/liyuxia713/