Professional Documents
Culture Documents
4 - Logistic Regression v2
4 - Logistic Regression v2
4 - Logistic Regression v2
BENE 4333
ARTIFICIAL INTELLIGENCE
By:
Wira Hidayat bin Mohd Saad
(PhD)
Logistic Regression
1
11/9/22
Classification
• Email: Spam / Not Spam?
• Online Transactions: Fraudulent (Yes / No)?
• Tumor: Malignant / Benign ?
Classification
hθ(x)
(Yes) 1
Malignant ?
0.5
(No) 0
Tumor Size Tumor Size
2
11/9/22
Classification
hθ(x)
(Yes) 1
Malignant ?
0.5
(No) 0
Tumor Size Tumor Size
Classification
3
11/9/22
Classification
Logistic Regression Model
1
ℎ! 𝑥 = 𝑔 𝜃 " 𝑥 → 𝑔 𝑧 = ………4.1
1 + 𝑒 #$
1
𝑔 𝑧
Sigmoid function = Logistic function
0.5
0 z
Example: If
4
11/9/22
Decision boundary
1
𝑔 𝑧
0.5
Suppose predict “ “ if 0 z
(𝜃 ! 𝑥 < 0) (𝜃 ! 𝑥 ≥ 0)
(𝜃 ! 𝑥 ≥ 0)
predict “ “ if
(𝜃 ! 𝑥 < 0)
Decision boundary
x2
1
Predict “ “ if
1 2 3 x1
Or in other word, Predict “ “ if
𝑥% + 𝑥& ≥ 3
10
5
11/9/22
Decision boundary
x2
1
Predict “ “ if
1 2 3 x1
Or in other word, Predict “ “ if
Decision boundary 𝑥% + 𝑥& ≥ 3
11
1
…..(4.2)
-1 1 x1
-1
Let’s 𝜃" = −1, 𝜃# = 0, 𝜃$ = 0, 𝜃% = 1, 𝜃& = 1,
Predict “ “ if
x2
If 𝑥%& + 𝑥&& = 1 , we can draw the circle.
x1
12
6
11/9/22
Cost Function
Training set:
m examples
13
Cost Function
Linear regression cost function :
14
7
11/9/22
Cost Function
If y = 1 If y = 1,
q Cost = 0 if prediction is correct
Cost
q As ℎ! 𝑥 → 0, cost → ∞
q Captures intuition if ℎ! 𝑥 =0,
but y = 1, we will penalize the
0 1 learning algorithm by a very large
cost.
Slide credit: Andrew Ng
15
Cost Function
If y = 1 If y = 0
If y = 0
q Cost = 0 if prediction is correct
Cost
q As (1 − ℎ! 𝑥 ) → 1, cost → ∞
q Captures intuition that larger
mistake should get larger penalties.
0 1
16
8
11/9/22
17
Gradient descent
Want :
Repeat
18
9
11/9/22
Multi-class classification
Disease diagnosis: health / cold / flu / pneumonia
19
Multi-class classification
• For 2 classes classification:
6 89: 52<
ℎ5 𝑥 = = …… (4.2)
6789: ;52< 6789: 52<
20
10
11/9/22
Multi-class classification
• Split into One vs Rest:
21
Any Question??
22
11