Professional Documents
Culture Documents
Lec03-1 Linear Regression
Lec03-1 Linear Regression
AVAILab
Autonomous Vehicles &
Artificial Intelligence
Laboratory
• The Regression Problem
• Simple Linear Regression
• Multiple Linear Regression
• Suppose we know/estimate the shape of the function that governs the system, g(x).
• Squaring the difference also makes the sign of the differences irrelevant.
• Squaring the difference assigns higher pressure to reducing large differences.
Learning Algorithm
(training of hypothesis / optimisation)
Hypothesis
g(x)
Price [£] = a0 + a ∙ x
17.5833
5.5833
4.2500
0.2500
• Due to time constraints, we will use Matlab’s fminunc built-in function to solve
the general optimisation problem embedded in the general regression problem.
• For Linear Regression, there is also a straightforward closed-form solution:
𝑛 𝑛
1 2 1 2
𝑀𝑆𝐸 = ⋅ 𝑦𝑖 − 𝑔 𝑥𝑖 = ⋅ 𝑦𝑖 − 𝑎0 − 𝑎1 ⋅ 𝑥𝑖
𝑛 𝑛
𝑖=1 𝑖=1
𝑛
𝜕𝑀𝑆𝐸 2
= − ⋅ 𝑦𝑖 − 𝑎0 − 𝑎1 ⋅ 𝑥𝑖 = 0
𝜕𝑎0 𝑛
𝑖=1
𝑛
𝜕𝑀𝑆𝐸 2
= − ⋅ 𝑥𝑖 ⋅ 𝑦𝑖 − 𝑎0 − 𝑎1 ⋅ 𝑥𝑖 = 0
𝜕𝑎1 𝑛
𝑖=1
Linear Regression Mauro S. Innocente
12 | 18
𝑛 𝑛 𝑛 𝑛 𝑛
𝑦𝑖 − 𝑎0 − 𝑎1 ⋅ 𝑥𝑖 = 𝑦𝑖 − 𝑎0 ⋅ 𝑛 − 𝑎1 ⋅ 𝑥𝑖 = 0 ⇒ 𝑎0 ⋅ 𝑛 + 𝑎1 ⋅ 𝑥𝑖 = 𝑦𝑖
𝑖=1 𝑖=1 𝑖=1 𝑖=1 𝑖=1
𝑛 𝑛 𝑛 𝑛 𝑛 𝑛 𝑛
𝑥𝑖 ⋅ 𝑦𝑖 − 𝑎0 − 𝑎1 ⋅ 𝑥𝑖 = 𝑥𝑖 ⋅ 𝑦𝑖 − 𝑥𝑖 ⋅ 𝑎0 − 𝑎1 ⋅ 𝑥𝑖 2 = 0 ⇒ 𝑎0 ⋅ 𝑥𝑖 + 𝑎1 ⋅ 𝑥𝑖 2 = 𝑥𝑖 ⋅ 𝑦𝑖
𝑖=1 𝑖=1 𝑖=1 𝑖=1 𝑖=1 𝑖=1 𝑖=1
• Operating,
𝜕𝑀𝑆𝐸
• Note that, if 𝑎0 = 0, the equation derived from
𝜕𝑎0
= 0 does not apply. Then,
σ𝑛𝑖=1 𝑥𝑖 ⋅ 𝑦𝑖
𝑎1 = = 0.03403
σ𝑛𝑖=1 𝑥𝑖 2
Price [£] = a0 + a ∙ x
Here the input vector x (predictor / independent variable) is no longer a scalar but a 4D vector.
• For multiple linear regression, the approximation function is given by:
𝑔(𝐱) = 𝐚 ⋅ 𝐱 = 𝑎0 ⋅ 𝑥0 + 𝑎1 ⋅ 𝑥1 +. . . +𝑎𝑚 ⋅ 𝑥𝑚 (vector notation, inner product)
• In matrix notation,
𝑔(𝐱) = 𝐚T ⋅ 𝐱 = 𝑎0 ⋅ 𝑥0 + 𝑎1 ⋅ 𝑥1 +. . . +𝑎𝑚 ⋅ 𝑥𝑚
• Data Normalisation: If different variables have different orders or magnitude, scaling them to
the same order (e.g. [0, 1]) speeds-up convergence.
• Mean Normalisation: Technique used to work with zero-mean variables.