Lecture 3
Lecture 3
Regression: Part 1
North South University Source: Andrew NG Lectures CSE465 Md. Shahriar Hussain
Linear Neural Networks (LNNs)
North South University Source: Andrew NG Lectures CSE465 Md. Shahriar Hussain 2
Linear Neural Networks (LNNs)
North South University Source: Andrew NG Lectures CSE465 Md. Shahriar Hussain 3
Linear Neural Networks (LNNs)
Classification
Regression Problem
Problem
North South University Source: Andrew NG Lectures CSE465 Md. Shahriar Hussain 4
Linear Neural Networks (LNNs)
• For Regression,
– There will be only aggregation
– No activation function is needed.
North South University Source: Andrew NG Lectures CSE465 Md. Shahriar Hussain 7
Linear Regression Example
North South University Source: Andrew NG Lectures CSE465 Md. Shahriar Hussain 8
Linear Regression Example
North South University Source: Andrew NG Lectures CSE465 Md. Shahriar Hussain 9
Linear Regression Example
North South University Source: Andrew NG Lectures CSE465 Md. Shahriar Hussain 10
Linear Regression Example
A Line of best
fit/Regression Line is
a straight line that
represents the best
approximation of a
scatter plot of data
points
North South University Source: Andrew NG Lectures CSE465 Md. Shahriar Hussain 11
Linear Regression Example
North South University Source: Andrew NG Lectures CSE465 Md. Shahriar Hussain 12
Data Set Description
North South University Source: Andrew NG Lectures CSE465 Md. Shahriar Hussain 13
Data Set Description
x (1) = 2104
x (2) = 1416
y (1) = 460
(x, y)= One Training Example
(x (i), y (i))= ith Training example y (2) = 232
North South University Source: Andrew NG Lectures CSE465 Md. Shahriar Hussain 14
Hypothesis
Training Set
Learning Algorithm
• How do we represent h ?
𝑦 𝑥 =
North South University Source: Andrew NG Lectures CSE465 Md. Shahriar Hussain 16
Hypothesis
• A cost function lets us figure out how to fit the best straight line to our data
North South University Source: Andrew NG Lectures CSE465 Md. Shahriar Hussain 17
Hypothesis
North South University Source: Andrew NG Lectures CSE465 Md. Shahriar Hussain 19
Cost Function
minimize
Ө0 Ө1
• We need to choose Ө0 and Ө1 in a way that the result of the function will be minimized for all
m training example. This equation is called cost function.
J(Ө0 , Ө1)=
minimize
Ө0 Ө1 J(Ө0 , Ө1)
North South University Source: Andrew NG Lectures CSE465 Md. Shahriar Hussain 20
Cost Function
Cost Function:
Goal:
North South University Source: Andrew NG Lectures CSE465 Md. Shahriar Hussain 21
Cost Function Calculation
North South University Source: Andrew NG Lectures CSE465 Md. Shahriar Hussain 22
Cost Function Calculation
3
3
2
2
1
1
0
0 -0.5 0 0.5 1 1.5 2 2.5
0 1 2 3
For, θ1 = 1
J(θ1) = 1/2*3 [0+0+0]=0
North South University Source: Andrew NG Lectures CSE465 Md. Shahriar Hussain 23
Cost Function Calculation
For, θ1 = 0.5
J(θ1) = ?
North South University Source: Andrew NG Lectures CSE465 Md. Shahriar Hussain 24
Cost Function Calculation
North South University Source: Andrew NG Lectures CSE465 Md. Shahriar Hussain 25
Cost Function Calculation
For, θ1 = 0
J(θ1) = ?
North South University Source: Andrew NG Lectures CSE465 Md. Shahriar Hussain 26
Cost Function Calculation
North South University Source: Andrew NG Lectures CSE465 Md. Shahriar Hussain 27
Cost Function Calculation
North South University Source: Andrew NG Lectures CSE465 Md. Shahriar Hussain 28
Important Equations
Hypothesis:
Parameters:
Cost Function:
Goal:
North South University Source: Andrew NG Lectures CSE465 Md. Shahriar Hussain 29
Cost Function for two parameters
500
400
300
Price ($)
200
in 1000’s
100
0
0 500 1000 1500 2000 2500 3000
North South University Source: Andrew NG Lectures CSE465 Md. Shahriar Hussain 30
Cost Function for two parameters
North South University Source: Andrew NG Lectures CSE465 Md. Shahriar Hussain 31
Cost Function for two parameters
North South University Source: Andrew NG Lectures CSE465 Md. Shahriar Hussain 32
Cost Function for two parameters
North South University Source: Andrew NG Lectures CSE465 Md. Shahriar Hussain 33
Cost Function for two parameters
North South University Source: Andrew NG Lectures CSE465 Md. Shahriar Hussain 34
Cost Function for two parameters
North South University Source: Andrew NG Lectures CSE465 Md. Shahriar Hussain 35
Cost Function for two parameters
North South University Source: Andrew NG Lectures CSE465 Md. Shahriar Hussain 36
Cost Function for two parameters
North South University Source: Andrew NG Lectures CSE465 Md. Shahriar Hussain 37
Gradient descent
• Outline:
North South University Source: Andrew NG Lectures CSE465 Md. Shahriar Hussain 38
Gradient descent
North South University Source: Andrew NG Lectures CSE465 Md. Shahriar Hussain 39
Gradient descent
North South University Source: Andrew NG Lectures CSE465 Md. Shahriar Hussain 41
Gradient Descent Algorithm
North South University Source: Andrew NG Lectures CSE465 Md. Shahriar Hussain 42
Gradient Descent Algorithm
North South University Source: Andrew NG Lectures CSE465 Md. Shahriar Hussain 43
Gradient Descent Algorithm
North South University Source: Andrew NG Lectures CSE465 Md. Shahriar Hussain 44
Gradient Descent Algorithm
North South University Source: Andrew NG Lectures CSE465 Md. Shahriar Hussain 45
Gradient Descent Algorithm
North South University Source: Andrew NG Lectures CSE465 Md. Shahriar Hussain 46
Gradient Descent Algorithm
North South University Source: Andrew NG Lectures CSE465 Md. Shahriar Hussain 47
Learning Rate
North South University Source: Andrew NG Lectures CSE465 Md. Shahriar Hussain 48
Learning Rate
North South University Source: Andrew NG Lectures CSE465 Md. Shahriar Hussain 49
Learning Rate
North South University Source: Andrew NG Lectures CSE465 Md. Shahriar Hussain 50
Learning Rate
North South University Source: Andrew NG Lectures CSE465 Md. Shahriar Hussain 51
Local Minima
• Local minimum: value of the loss function is minimum at that point in a local
region.
• Global minima: value of the loss function is minimum globally across the
entire domain the loss function
North South University Source: Andrew NG Lectures CSE465 Md. Shahriar Hussain 52
Local Minima
at local minima
Global minima
North South University Source: Andrew NG Lectures CSE465 Md. Shahriar Hussain 53
Gradient Descent Calculation
North South University Source: Andrew NG Lectures CSE465 Md. Shahriar Hussain 54
Gradient Descent Calculation
North South University Source: Andrew NG Lectures CSE465 Md. Shahriar Hussain 55
• Reference:
– Andrew NG Lectures on Machine Learning, Standford University
North South University Source: Andrew NG Lectures CSE465 Md. Shahriar Hussain 56