Hacker News new | ask | show | jobs
by FabHK 3191 days ago
BTW, I think one important take-away for programmers is:

Don't invert matrices.

For example, the solution for the least squares (=linear regression) problem is

  beta^hat = (X'X)^-1 X'y
and you might think that the best way to compute it is to compute X'X, invert it, do the multiplication, yada yada yada. But it's really better to just ask your library (Matlab, LAPACK, ...) to solve the problem for you, and it'll probably do a QR decomposition. For small problems, it doesn't really matter, but for big problems you'll be both faster and more accurate.
1 comments

Excellent John D. Cook piece on the same subject: https://www.johndcook.com/blog/2010/01/19/dont-invert-that-m...
That's a slightly different issue: the issue with solving normal equations directly is that the condition number of X^\top X is the square of the condition number of X, so it's much more significant than lu-vs-inv. It can matter a great deal for ill-conditioned linear regression problems where some features resemble each other.