Course吴恩达的机器学习课程——week2 编程作业小结

Course吴恩达的机器学习课程——week2 编程作业小结

编辑的文档

warmUpExercise

A = eye(5);

featureNormalize

mu = mean(X);

sigma = std(X,1);

for i = 1:size(X,2)
    X_norm(:,i)=   (X(:,i) - mu(i)) /sigma(i) ;
end

gradientDescent && gradientDescentMulti

theta = theta - alpha * (1/m)* ((X*theta - y)' * X)';

computeCost && computeCostMulti

J = 1/(2*m)*sum( (X*theta -y).^2 )

plotData

plot(x,y,'rx','MarkerSize',10);
ylabel('Profit in $10,000s');
xlabel('Population of City in 10,000s');

normalEqn

theta = pinv(X'*X)*X'*y;

梯度下降计算结果

t = [1650 3];
t = (t - mu )./sigma;
price = [1 t]* theta;

normal equation计算结果

price = [1 1650 3]*theta;

猜你喜欢

转载自blog.csdn.net/listep/article/details/78254247