【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;
 
posted @ 2012-09-19 19:32  liyuxia713  阅读(329)  评论(0编辑  收藏  举报