Chapter 3 - Logistic Regression
Chapter 3 - Logistic Regression
Logistic Regression
MSc. Nguyen Khanh Loi
[email protected]
8/2023
MSc Nguyen Khanh Loi
Content
Ø Classification
Ø Hypothesis Representation
Ø Decision boundary
Ø Cost function
Ø Simplified cost function and gradient descent
Ø Advanced optimization
Ø Multi-class classification: One-vs-all
2
MSc Nguyen Khanh Loi
Classification
3
MSc Nguyen Khanh Loi
Classification
4
MSc Nguyen Khanh Loi
Classification
(Yes) 1
Malignant ?
(No) 0
Tumor Size Tumor Size
5
MSc Nguyen Khanh Loi
Classification
Classification: y = 0 or 1
Logistic Regression:
6
MSc Nguyen Khanh Loi
Hypothesis Representation
7
MSc Nguyen Khanh Loi
Hypothesis Representation
Sigmoid function
Logistic function
8
MSc Nguyen Khanh Loi
Interpretation of Hypothesis Output
Example: If
9
MSc Nguyen Khanh Loi
Decision boundary
10
MSc Nguyen Khanh Loi
Decision boundary
Logistic regression
Suppose predict “ “ if
predict “ “ if
11
MSc Nguyen Khanh Loi
Decision boundary
Logistic regression
When is ?
𝑔 𝑧 ≥ 0.5
𝑧≥0
𝜃 !𝑥 ≥ 0 𝜃 !𝑥 < 0
12
MSc Nguyen Khanh Loi
Decision boundary
2 features: x1, x2
Example: x2
𝜃! = −3 3
2
𝜃" = 1
1
𝜃# = 1
1 2 3 x1
−3 + 𝑥! + 𝑥" = 0
Predict “ “ if
13
MSc Nguyen Khanh Loi
Non-linear decision boundaries
x2
Choose: 𝜃! = −1, 𝜃" = 0, 𝜃# = 0, 𝜃$ = 1,
𝜃% = 1 1
Predict “ “ if
14
MSc Nguyen Khanh Loi
Non-linear decision boundaries
x2 x2
x1 x1
15
MSc Nguyen Khanh Loi
Cost function
16
MSc Nguyen Khanh Loi
Cost function
m examples
Training set:
Linear regression:
“convex” “non-convex”
18
MSc Nguyen Khanh Loi
Logistic regression cost function
If y = 1
0 1
19
MSc Nguyen Khanh Loi
Logistic regression cost function
If y = 0
0 1
20
MSc Nguyen Khanh Loi
Simplified cost function and gradient descent
21
MSc Nguyen Khanh Loi
Logistic regression cost function
maximum likelihood
To fit parameters :
22
MSc Nguyen Khanh Loi
Gradient Descent
Want :
Repeat
23
MSc Nguyen Khanh Loi
Gradient Descent
Want :
Repeat
24
MSc Nguyen Khanh Loi
Advanced optimization
25
MSc Nguyen Khanh Loi
Optimization algorithm
Gradient descent:
Repeat
26
MSc Nguyen Khanh Loi
Optimization algorithm
27
MSc Nguyen Khanh Loi
Multi-class classification: One-vs-all
28
MSc Nguyen Khanh Loi
Multiclass classification
29
MSc Nguyen Khanh Loi
Multiclass classification
x2 x2
x1 x1
30
MSc Nguyen Khanh Loi
One-vs-all (one-vs-rest):
x2
x1
x2 x2
x1 x1
x2
Class 1:
Class 2:
Class 3:
x1
31
MSc Nguyen Khanh Loi
One-vs-all
32
MSc Nguyen Khanh Loi
Practice 1
33
MSc Nguyen Khanh Loi