You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
19 lines
542 B
Matlab
19 lines
542 B
Matlab
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.
|
|
%
|
|
|
|
theta = pinv(X' * X) * X' * y;
|
|
|
|
|
|
% ============================================================
|
|
|
|
end
|