吴恩达机器学习 - 正规函数

题目链接:点击打开链接


老规矩先贴笔记

这里写图片描述


按照公式写代码就可以啦:

normalEqn.m:

function [theta] = normalEqn(X, y)
%NORMALEQN Computes the closed-form solution to linear regression 
%   NORMALEQN(X,y) computes the closed-form solution to linear 
%   regression using the normal equations.

theta = zeros(size(X, 2), 1);

% ====================== YOUR CODE HERE ======================
% Instructions: Complete the code to compute the closed form solution
%               to linear regression and put the result in theta.
%

% ---------------------- Sample Solution ----------------------

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


% -------------------------------------------------------------


% ============================================================

end

猜你喜欢

转载自blog.csdn.net/wyg1997/article/details/80725963