1
0
Fork 0

Linear regressing using the normal equation

master
neingeist 10 years ago
parent ad9ab582de
commit ba377e29ba

@ -1,6 +1,6 @@
function [theta] = normalEqn(X, y) function [theta] = normalEqn(X, y)
%NORMALEQN Computes the closed-form solution to linear regression %NORMALEQN Computes the closed-form solution to linear regression
% NORMALEQN(X,y) computes the closed-form solution to linear % NORMALEQN(X,y) computes the closed-form solution to linear
% regression using the normal equations. % regression using the normal equations.
theta = zeros(size(X, 2), 1); theta = zeros(size(X, 2), 1);
@ -10,12 +10,7 @@ theta = zeros(size(X, 2), 1);
% to linear regression and put the result in theta. % to linear regression and put the result in theta.
% %
% ---------------------- Sample Solution ---------------------- theta = pinv(X' * X) * X' * y;
% -------------------------------------------------------------
% ============================================================ % ============================================================