Docsity

Least Squares Regression: Solving for the Coefficients' Matrix B, Lecture notes of Computer Engineering and Programming

Toggle sidebar
bg1
T
-
N
B
n=1
(matrix
form)
Min
Cuector form)
Least Squares Equations
min t & ly - xn B²
- Minimize MsE by :
hlý-tßl
-
ß N
Similar to ID case, we can take gradient and set to
Ollo) y -XB1_) = () (x+x)B -(*) x+y = 0
(
This yields: XFxß Exty
XIX
Solving for B
-If XTX is invertible, we can take a matrix inverse
to solve for B
B = (x+x)"xty
But XIX is not always invertibu
- The inverse
exists if and only if X has linearly
x
Independent columns
What does it mean when X² X is not invertible?
- Infinite possible solutions
- Choose the one where ß is smallest
Example
5 data
5 data points
with 2 features and a target (x,,X2 24)
(1, 2,10),(-3,6,0), (0,0,3),(1,-1,4), (5,-2,20)
model:
y = a, x, +Q X₂ tb . B=(a, a, b)
a, x2 b B (T
target
X
vector
y =
s feature
matrix
2
10
16
O
20
.2
Using numpy, we get
Therefore, our model

Partial preview of the text

Download Least Squares Regression: Solving for the Coefficients' Matrix B and more Lecture notes Computer Engineering and Programming in PDF only on Docsity!

T

N B

n= (matrix form) Min Cuector form) Least Squares Equations min t & ly - xn B²

  • Minimize MsE by :

hlý-tßl

ß N Similar to ID case, we can take gradient and set to Ollo) y -XB1_) = () (x+x)B -(*) x+y = 0 ( This yields: XFxß Exty XIX Solving for B -If XTX is invertible, we can take a matrix inverse to solve for B B = (x+x)"xty But XIX is not always invertibu

  • The inverse

exists if and only if X has linearly x Independent columns What does it mean when X² X is not invertible?

  • Infinite possible solutions
  • Choose the one where ß is smallest

Example 5 data 5 data points with 2 features and a target (x,,X2 24) (1, 2,10),(-3,6,0), (0,0,3),(1,-1,4), (5,-2,20) model: y = a, x, +Q X₂ tb. B=(a, a, b) a, x2 b B (T target X vector y = s feature matrix 2 10 16 O 20 . Using numpy, we get Therefore, our model