Skip to content

Instantly share code, notes, and snippets.

@sbyrnes
Created May 27, 2012 02:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sbyrnes/2797087 to your computer and use it in GitHub Desktop.
Save sbyrnes/2797087 to your computer and use it in GitHub Desktop.
Implementation of the Normal Equation
// FORMULA: theta = pinv(X'*X)*X'*y;
function generateTheta(X, y)
{
// Get the transpose of X
Xt = X.transpose();
// Multiple X by its transpose
var Xmain = X.x(Xt);
// Get the inverse of the result of multiplying X by its transpose
var Xinv = Xmain.inverse();
// Get the transpose of X' times y
var Atd = X.x(y);
// Theta is the result of the multiplication of both
var theta = Xinv.x(Atd);
return theta;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment