Skip to content

Week 1 Lecture 3

Linear regression

Derivatives recap

Multivariate chain rule

Linear regression

Predicting target variable ๐‘ฆโˆˆโ„๐‘š, based on ๐‘ฅโˆˆ๐’ณ๏ธ€=โ„๐‘‘ (for now, let ๐‘š=1)

๐‘ฆฬ‚=๐‘“(๐‘ฅ)=โˆ‘๐‘–=1๐‘‘๐‘ค๐‘–๐‘ฅ๐‘–+๐‘=๐‘ค๐‘‡๐‘ฅ+๐‘

(where ๐‘คโˆˆโ„๐‘‘ and ๐‘โˆˆโ„)

We can get rid of the ๐‘ parameter by defining: ๐‘ฅฬƒ๐‘‡=(๐‘ฅ1,๐‘ฅ2,โ€ฆ,๐‘ฅ๐‘‘,1) and ๐‘คฬƒ๐‘‡=(๐‘ค1,โ€ฆ,๐‘ค๐‘‘,๐‘)

Then:

๐‘ฆฬ‚=๐‘“(๐‘ฅฬƒ)=๐‘คฬƒ๐‘‡๐‘ฅฬƒ

(Basically add another dimension ranging from 1 to ๐‘ (from ๐‘ฅ to ๐‘ค), so the equation works pretty much the same) what

Letโ€™s omit the tilde for easier usage.

The training data can be gathered into a matrix:

๐‘‹=(๐‘ฅ11๐‘ฅ12โ€ฆ๐‘ฅ1๐‘‘1๐‘ฅ21๐‘ฅ22โ€ฆ๐‘ฅ2๐‘‘1โ‹ฎโ‹ฎโ‹ฑโ‹ฎโ‹ฎ๐‘ฅ๐‘1๐‘ฅ๐‘2โ€ฆ๐‘ฅ๐‘๐‘‘1)

You can index it with ๐‘ฅ (even partially). The notation [๐‘ฅ๐‘–]๐‘— is to keep it โ€˜simpleโ€™.

Our goal is still to minimize risk.

Using squared loss: โ„“(๐‘ฆ,๐‘ฆฬ‚)=(๐‘ฆโˆ’๐‘ฆฬ‚)2 (Mean squared error)

If ๐‘‹๐‘‡๐‘‹ has full rank, optimal parameters are given by:

๐‘คโ‹†=(๐‘‹๐‘‡๐‘‹)โˆ’1๐‘‹๐‘‡โŸ๐‘‹โ€ ๐‘ฆ

(๐‘‹โ€ ) is the pseudoinverse

note: vectors wonโ€™t produce an outer product with full rank (just 1)

Deriving Linear Regression

Overdetermined case

Probably see the slides

Underdetermined case

At times the data points are fewer than the the amount of parameters available, the (resulting matrix) rank will not be full, and many solution can give us 0 error. In that case, minimization of the norm might be a good idea.

We want to find the weights with minimal norm, that still goes through every datapoint:

๐‘คโ‹†=argmin๐‘คโˆˆโ„๐‘‘โ€–๐‘คโ€–2 (norm) such that โˆ€๐‘–:๐‘ค๐‘‡๐‘ฅ๐‘–โˆ’๐‘ฆ๐‘–=0 (linear constraint)

In this case, the gradient at the optimal point must be a linear combination of the normal (perpendicular) vectors of the constraint.

๐‘คโ‹†=๐‘‹๐‘‡(๐‘‹๐‘‡๐‘‹)โˆ’1โŸ๐‘‹โ€ ๐‘ฆ
Notice the order has changed
Singular value decomposition (SVD)
๐‘‹=๐‘ˆฮ“๐‘‰๐‘‡

for ๐‘Ÿ=min{๐‘,๐‘‘}

  • ๐‘ˆโˆˆโ„๐‘ร—๐‘Ÿ (semi-orthogonal)
  • ฮ“=diag(๐›พ1,โ€ฆ,๐›พ๐‘Ÿ)โˆˆโ„๐‘Ÿร—๐‘Ÿ with ๐›พ1โ‰ฅ๐›พ2โ‰ฅโ€ฆโ‰ฅ0
  • ๐‘‰โˆˆโ„๐‘‘ร—๐‘Ÿ semi-orthogonal

Computation is not includedโ€ฆ Exercise for the reader implementorโ€ฆ

๐‘‹โ€ =โœจ๏ธMagicโœจ๏ธโ†“๐‘‰ฮ“โˆ’1๐‘ˆ๐‘‡
Likelihood function

Also see the presentation