- #1
In this video we'll define something
called the cost function. This will let us
- #2
figure out how to fit the best possible
straight line to our data. In linear
- #3
regression we have a training set like
that shown here. Remember our notation M
- #4
was the number of training examples. So
maybe M=47. And the form of the
- #5
hypothesis, which we use to make
predictions, is this linear function. To
- #6
introduce a little bit more terminology,
these theta zero and theta one, right,
- #7
these theta i's are what I call the
parameters of the model. What we're
- #8
going to do in this video is talk about
how to go about choosing these two
- #9
parameter values, theta zero and theta
one. With different choices of parameters
- #10
theta zero and theta one we get different
hypotheses, different hypothesis
- #11
functions. I know some of you will
probably be already familiar with what I'm
- #12
going to do on this slide, but just to
review here are a few examples. If theta
- #13
zero is 1.5 and theta one is 0, then
the hypothesis function will look like
- #14
this. Right, because your hypothesis
function will be h( x) equals 1.5 plus
- #15
0 times x which is this constant value
function, this is flat at 1.5. If
- #16
theta zero equals 0 and theta one
equals 0.5, then the hypothesis will look
- #17
like this. And it should pass through this
point (2, 1), says you now have h(x) or
- #18
really some htheta(x) but
sometimes I'll just omit theta for
- #19
brevity. So, h(x) will be equal to just
0.5 times x which looks like that. And
- #20
finally if theta zero equals 1 and theta
one equals 0.5 then we end up with the
- #21
hypothesis that looks like this. Let's
see, it should pass through the (2, 2)
- #22
point like so. And this is my new h(x)
or my new htheta(x). All right? Well
- #23
you remember that this is
htheta(x) but as a shorthand
- #24
sometimes I just write this as h(x). In
linear regression we have a training set,
- #25
like maybe the one I've plotted here. What
we want to do is come up with values for
- #26
the parameters theta zero and theta one.
So that the straight line we get out
- #27
of this corresponds to a straight line
that somehow fits the data well. Like
- #28
maybe that line over there. So how do we
come up with values theta zero, theta one
- #29
that corresponds to a good fit to the
data? The idea is we're going to choose
- #30
our parameters theta zero, theta one so
that h(x), meaning the value we predict
- #31
on input x, that this at least close to
the values y for the examples in our
- #32
training set, for our training examples.
So, in our training set we're given a
- #33
number of examples where we know x decides
the house and we know the actual price of
- #34
what it's sold for. So let's try to
choose values for the parameters so that
- #35
at least in the training set, given the
x's in the training set, we make
- #36
reasonably accurate predictions for the y
values. Let's formalize this. So linear
- #37
regression, what we're going to do is that I'm
going to want to solve a minimization
- #38
problem. So I'm going to write minimize over theta
zero, theta one. And, I want this to be
- #39
small, right, I want the difference
between h(x) and y to be small. And one
- #40
thing I'm gonna do is try to minimize the
square difference between the output of
- #41
the hypothesis and the actual price of the
house. Okay? So let's fill in some
- #42
details. Remember that I was using the
notation (x(i), y(i)) to represent the
- #43
ith training example. So what I
want really is to sum over my training
- #44
set. Sum from i equals 1 to M of
the square difference between
- #45
this is the prediction of my hypothesis
when it is input the size of house number
- #46
i, right, minus the actual price that
house number i will sell for and I want to
- #47
minimize the sum of my training set sum
from i equals 1 through M of the
- #48
difference of this squared error,
square difference between the predicted
- #49
price of the house and the price
that it will actually sell for. And just
- #50
remind you of your notation M here was
the, the size of my training set, right,