Linear Algebra for Data Science in R
Eric Eager
Data Scientist at Pro Football Focus
Row Reduction (By Hand, Difficult for Big Problems)
Least Squares (If More Rows Than Columns - Used in Linear Regression)
Singular Value Decomposition (If More Columns Than Rows - Used in Principal Component Analysis)
Generalized or Pseudo-Inverse
library(MASS)
print(A)
[,1] [,2]
[1,] 2 3
[2,] -1 4
[3,] 1 7
ginv(A)
[,1] [,2] [,3]
[1,] 0.3333333 -0.30303030 0.03030303
[2,] 0.0000000 0.09090909 0.09090909
ginv(A)%*%A
[,1] [,2]
[1,] 1 -1.110223e-16
[2,] 0 1.000000e+00
A%*%ginv(A)
[,1] [,2] [,3]
[1,] 0.6666667 -0.3333333 0.3333333
[2,] -0.3333333 0.6666667 0.3333333
[3,] 0.3333333 0.3333333 0.6666667
print(A)
[,1] [,2]
[1,] 2 3
[2,] -1 4
[3,] 1 7
print(b)
1 7 8
x <- ginv(A)%*%b
A%*%x
[,1]
[1,] 1
[2,] 7
[3,] 8
Linear Algebra for Data Science in R