Lecture 3_Regression (1)
Lecture 3_Regression (1)
Boyu Wang
Department of Computer Science
University of Western Ontario
Motivation examples
1
Motivation examples
2
Motivation examples
3
Data
4
Terminology
I The outcome and time (which we are trying to predict) are called output
variables or targets.
5
Problem formulation
6
Problem formulation
h:X →Y
such that for a new example (x, y ), h(x) can correctly predict the value
of y .
I Key assumption: training and test data are sampled from the same
distribution.
7
Steps to solving a supervised learning problem
I Choose a hypothesis h ∈ H
8
Example: what hypothesis class should we choose?
6.5
5.5
y
4.5
3.5
0 1 2 3 4 5
x
9
Steps to solving a supervised learning problem
I Choose a hypothesis h ∈ H
10
Linear model
hw (x) = w > x + b
hw (x) = w > x
I How to choose w?
11
Error (cost) Minimization
13
Solve ∇J(w) = 0 using the definition
m
!
1X
∇J(w) = ∇w (hw (xi ) − yi )2
2
i=1
1 >
= ∇w (Xw − y ) (Xw − y )
2
1
= ∇w w > X > Xw − y > Xw − w > X > y + y > y
2
= X > Xw − X > y
X > Xw − X > y = 0
⇒X > Xw = X > y
⇒w = (X > X )−1 X > y
15
Linear regression summary
I Demo!
16
Predicting recurrence time based on tumor size
17
Geometric interpretation orthogonal projection
https://towardsdatascience.com/3-things-you-didnt-know-about-simple-linear-regression-b5a86362dd53
18
Probabilistic perspective of linear regression
19
Bayes rule in machine learning
20
Select a hypothesis by maximum a posteriori (MAP)
21
Maximum likelihood estimation
22
The log trick
23
Maximum likelihood for regression
24
Applying the log trick
25
Maximum likelihood and linear regression
I Under the assumption that the training examples are i.i.d. and
that we have Gaussian target noise, the maximum likelihood
solution is equivalent to the least-squares solution for linear
regression:
m
X
w = arg min (hw (xi ) − yi )2
w
i=1
26
Extending linear regression to more complex models
I Linear regression should be the first thing you try for real-valued
outputs!
27
Linear models in general
28
Linear models in general
29
Example basis functions: Polynomial
30
Example basis functions: Gaussian
31
Example basis functions: Sigmoidal
32
Polynomial regression
33
Example: second-order polynomial regression
34
Example: second-order polynomial regression
35
Example: second-order polynomial regression
36
Example: second-order polynomial regression
37
Higher-order polynomial regression: Order-2 fit
38
Higher-order polynomial regression: Order-3 fit
39
Higher-order polynomial regression: Order-4 fit
40
Higher-order polynomial regression: Order-5 fit
41
Higher-order polynomial regression: Order-6 fit
42
Higher-order polynomial regression: Order-7 fit
43
Higher-order polynomial regression: Order-8 fit
44
Higher-order polynomial regression: Order-9 fit
45
Overfitting and model selection
46