Lecture 6
Lecture 6
A Line of best
fit/Regression Line is
a straight line that
represents the best
approximation of a
scatter plot of data
points
x (1) = 2104
x (2) = 1416
y (1) = 460
(x, y)= One Training Example
(x (i), y (i))= ith Training example y (2) = 232
Training Set
Learning Algorithm
• How do we represent h ?
𝑦 𝑥 =
• A cost function lets us figure out how to fit the best straight line to our data
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)
Cost Function:
Goal:
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 CSE445 18
Cost Function Calculation
For, θ1 = 0.5
J(θ1) = ?
North South University Source: Andrew NG Lectures CSE445 19
Cost Function Calculation
For, θ1 = 0
J(θ1) = ?
North South University Source: Andrew NG Lectures CSE445 21
Cost Function Calculation
Hypothesis:
Parameters:
Cost Function:
Goal:
500
400
300
Price ($)
200
in 1000’s
100
0
0 500 1000 1500 2000 2500 3000
• Outline:
• 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
at local minima
Global minima