Lecture 4 - Cost Function
Lecture 4 - Cost Function
Lecture 4
Recall predicting housing prices example?
• Find a price for house 1250 sq.ft? 500000
Hypothesis:
‘s: Parameters of the model
How to choose ‘s ?
3
Model Representation
• More formally, in supervised learning, we have a data set and this
data set is called a training set.
• So for housing prices example, we have a training set of different
housing prices and our job is to learn from this data how to predict
prices of the houses
4
Notation:
•
Size in feet2 (x) Price ($) in 1000's (y)
• m = Number of training examples 2104 460
• x’s = “input” variable / features 1416 232
1534 315
• y’s = “output” variable / “target” 852 178
variable … …
• (x,y ) = one training example
• So, if we have size and prices of 47 houses, what is
• (x y )= i training example
i, i, th
m?
47
• What is x2
1416
• What is y2
232 5
Training Set • Training set like our training set of
housing prices
• We feed that to our learning
algorithm.
Learning Algorithm • It is the job of a learning algorithm
to then output a function h
• h is a function that takes as input,
the size of a house x and it tries to
Size of h Estimated output the estimated value of y for
house price the corresponding house.
• h is a function that maps from x's to
y's
6
The Hypothesis Function h
hθ(x)=θ0 + θ1x
We give to hθ(x)= values for θ0 and θ1 to get our output 'y'.
This model is called linear regression with one variable or Univariate linear
regression
7
500000
400000
300000
hθ(x)=θ0 +
200000
θ1x
100000
0
500 1000 1500 2000 2500 3000
8
• We have to minimize the difference
between h(x) and y
y • ( h(x) – y)
Where h(x) is what we are predicting and y is
the actual output
• Minimize the square difference between
x the output of the hypothesis and the actual
price of a house
11
“Cost” Function
• Coss/ Loss in Machine learning helps us understand the difference
between the predicted value & the actual value.
• The Function used to quantify this loss during the training phase in the
form of a single real number is known as “Loss Function”.
• Loss function: Used when we refer to the error for a single training
example.
• Cost function: Used to refer to an average of the loss functions over an
entire training dataset.
Why use a Cost Function?