1.12 Machine Learning Overview | Cost function intuition --[Machine Learning | Andrew Ng]
 We've seen the mathematical definition of the cost function. Now let's build some intuition about what the cost function is really doing. In this video, we'll walk through one example to see how the cost function can be used to find the best parameters for your model. I know this video is a little bit longer than the others, but bear with me, I think it'll be worth it. To recap, here's what we've seen about the cost function so far. You want to fit a straight line to the training data, so you have this model fwb of x is w times x plus b. And here the model's parameters are w and b. Now depending on the values chosen for these parameters, you get different straight lines like this. And you want to find values for w and b so that the straight line fits the training data well. To measure how well a choice of w and b fits the training data, you have a cost function j. And what the cost function j does is it measures the difference between the model's predictions and the actual true values for y. What you see later is that linear regression would try to find values for w and b that make a j of w be as small as possible. In math, we write it like this. We want to minimize j as a function of w and b. So now, in order for us to better visualize the cost function j, let's work with a simplified version of the linear regression model. We're going to use the model fw of x is w times x. You can think of this as taking the original model on the left and getting rid of the parameter b or setting the parameter b equal to zero. So it just goes away from the equation. So f is now just w times x. So you now have just one parameter w and your cost function j looks similar to what it was before, taking the difference and squaring it, except that now f is equal to w times xi and j is now a function of just w. And the goal becomes a little bit different as well because you have just one parameter w, not w and b. So with this simplified model, the goal is to find a value for w that minimizes j of w. To see this visually, what this means is that if b is set to zero, then f defines a line that looks like this. And you see that the line passes through the origin here because when x is zero, well, f of x is zero too. Now using this simplified model, let's see how the cost function changes as you choose different values for the parameter w. In particular, let's look at graphs of the model f of x and the cost function j. I'm going to plot these side by side and you'll be able to see how the two are related. First notice that for f subscript w, when the parameter w is fixed, that is, is always a constant value, then f w is only a function of x, which means that the estimated value of y depends on the value of the input x. In contrast, looking to the right, the cost function j is a function of w, where w controls the slope of the line defined by f w, so the cost defined by j depends on a parameter, in this case, the parameter w. So let's go ahead and plot these functions f w of x and j of w side by side so you can see how they are related. We'll start to the model that is the function f w of x on the left. Here the input feature x is on the horizontal axis and the output value y is on the vertical axis. Here's a plot of three points representing the trading set at positions 1 1, 2 2, and 3 3. Let's pick a value for w, say w is 1. So for this choice of w, the function f w looks like this straight line with a slope of 1. Now what you can do next is calculate the cost j when w equals 1. So you may recall that the cost function is defined as follows, it's the squared error cost function. So if you substitute f w of x i with w times x i, the cost function looks like this, where this expression is now w times x i minus y i. So for this value of w, it turns out that the error term inside the cost function, this w times x i minus y i is equal to zero for each of the three data points. Notice for this data set, when x is 1, then y is 1. When w is also 1, then f of x equals 1. So f of x equals y for this first training example, and the difference is zero. Plugging this into the cost function j, you get zero squared. Similarly, when x is 2, then y is 2, and f of x is also 2. So again, f of x equals y for the second training example. In the cost function, the squared error for the second example is also zero squared. Finally, when x is 3, then y is 3, and f of 3 is also 3. In the cost function, the third squared error term is also zero squared. So for all three examples in this training set, f of x i equals y i for each training example i. So f of x i minus y i is zero. So for this particular data set, when w is 1, then the cost j is equal to zero. Now what you can do on the right is plot the cost function j. And notice that because the cost function is a function of the parameter w, the horizontal axis is now labeled w and not x. And the vertical axis is now j and not y. So you have j of 1 equals to zero. In other words, when w equals 1, j of w is zero. So let me go ahead and plot that. Now let's look at how f and j change for different values of w. w can take on a range of values, right? So w can take on negative values, w can be zero, and it can take on positive values too. So what if w is equal to 0.5 instead of 1? What would these graphs look like then? Let's go ahead and plot that. So let's set w to be equal to 0.5. And in this case, the function f of x now looks like this, is aligned with a slope equal to 0.5. And let's also compute the cost j when w is 0.5. Recall that the cost function is measuring the squared error or difference between the estimated value that is y hat i, which is f of x i, and the true value that is y i for each example i. So visually you can see that the error or difference is equal to the height of this vertical line here when x is equal to 1, because this little line is the gap between the actual value of y and the value that the function f predicted, which is a bit further down here. So for this first example, when x is 1, f of x is 0.5, so the squared error on the first example is 0.5 minus 1 squared. Remember the cost function will sum over all the training examples in the training set. So let's go on to the second training example. When x is 2, the model is predicting f of x is 1, and the actual value of y is 2. So the error for the second example is equal to the height of this little line segment here, and the squared error is the square of the length of this line segment, so you get 1 minus 2 squared. Let's do the third example. Repeating this process, the error here, also shown by this line segment, is 1.5 minus 3 squared. Next we sum up all of these terms, which turns out to be equal to 3.5. Then we multiply this term by 1 over 2m, where m is the number of training examples. Since there are three training examples, m equals 3, so this is equal to 1 over 2 times 3, where this m here is 3. If we work out the math, this turns out to be 3.5 divided by 6, so the cost j is about 0.58. Let's go ahead and plot that over there on the right. Now let's try one more value for w. How about if w equals 0? What do the graphs for f and j look like when w is equal to 0? It turns out that if w is equal to 0, then f of x is just this horizontal line that is exactly on the x-axis, and so the error for each example is a line that goes from each point down to the horizontal line that represents f of x equals 0. So the cost j when w equals 0 is 1 over 2m times the quantity 1 squared plus 2 squared plus 3 squared, and that's equal to 1 over 6 times 14, which is about 2.33. So let's plot this point where w is 0 and j of 0 is 2.33 over here. And you can keep doing this for other values of w. Since w can be any number, it can also be a negative value, so if w is negative 0.5, then the line f is a downward sloping line like this. It turns out that when w is negative 0.5, then you end up with an even higher cost around 5.25, which is this point up here. And you can continue computing the cost function for different values of w and so on and plot these, right? So it turns out that by computing a range of values, you can slowly trace out what the cost function j looks like. And that's what j is. To recap, each value of parameter w corresponds to a different straight line fit, f of x, on the graph to the left. And for the given training set, that choice for a value of w corresponds to a single point, a single point, on the graph on the right. Because for each value of w, you can calculate a cost j of w. For example, when w equals 1, this corresponds to this straight line fit through the data. And it also corresponds to this point on the graph of j, where w equals 1 and the cost j of 1 equals 0. Whereas when w equals 0.5, this gives you this line, which has a smaller slope. And this line, in combination with the training set, corresponds to this point on the cost function graph at w equals 0.5. So for each value of w, you wind up with a different line and its corresponding cost j of w. And you can use these points to trace out this plot on the right. Given this, how can you choose the value of w that results in the function f fitting the data well? Well, as you can imagine, choosing a value of w that causes j of w to be as small as possible seems like a good bet. J is the cost function that measures how big the squared errors are. So choosing w that minimizes these squared errors, makes them as small as possible, would give us a good model. In this example, if you were to choose the value of w that results in the smallest possible value of j of w, you'd end up picking w equals 1. And as you can see, that's actually a pretty good choice. This results in a line that fits the training data very well. So that's how in linear regression, you use the cost function to find the value of w that minimizes j. Or in the more general case, when we had parameters w and b rather than just w, you find the values of w and b that minimize j. So to summarize, you saw plots of both f and j and work through how the two are related. As you vary w or vary w and b, you end up with different straight lines. And when that straight line passes close to data, the cost j is small. So the goal of linear regression is to find the parameters w or w and b that results in the smallest possible value for the cost function j. Now in this video, we worked through our example with a simplified problem using only w. In the next video, let's visualize what the cost function looks like for the full version of linear regression using both w and b. And you see some cool 3D plots. Let's go to the next video.
[{"start": 0.0, "end": 5.76, "text": " We've seen the mathematical definition of the cost function."}, {"start": 5.76, "end": 10.28, "text": " Now let's build some intuition about what the cost function is really doing."}, {"start": 10.28, "end": 14.88, "text": " In this video, we'll walk through one example to see how the cost function can be used to"}, {"start": 14.88, "end": 17.740000000000002, "text": " find the best parameters for your model."}, {"start": 17.740000000000002, "end": 21.400000000000002, "text": " I know this video is a little bit longer than the others, but bear with me, I think it'll"}, {"start": 21.400000000000002, "end": 22.400000000000002, "text": " be worth it."}, {"start": 22.400000000000002, "end": 26.98, "text": " To recap, here's what we've seen about the cost function so far."}, {"start": 26.98, "end": 33.52, "text": " You want to fit a straight line to the training data, so you have this model fwb of x is w"}, {"start": 33.52, "end": 35.88, "text": " times x plus b."}, {"start": 35.88, "end": 40.16, "text": " And here the model's parameters are w and b."}, {"start": 40.16, "end": 45.44, "text": " Now depending on the values chosen for these parameters, you get different straight lines"}, {"start": 45.44, "end": 47.24, "text": " like this."}, {"start": 47.24, "end": 53.120000000000005, "text": " And you want to find values for w and b so that the straight line fits the training data"}, {"start": 53.120000000000005, "end": 54.480000000000004, "text": " well."}, {"start": 54.48, "end": 61.559999999999995, "text": " To measure how well a choice of w and b fits the training data, you have a cost function"}, {"start": 61.559999999999995, "end": 63.36, "text": " j."}, {"start": 63.36, "end": 69.03999999999999, "text": " And what the cost function j does is it measures the difference between the model's predictions"}, {"start": 69.03999999999999, "end": 73.6, "text": " and the actual true values for y."}, {"start": 73.6, "end": 78.92, "text": " What you see later is that linear regression would try to find values for w and b that"}, {"start": 78.92, "end": 83.4, "text": " make a j of w be as small as possible."}, {"start": 83.4, "end": 85.84, "text": " In math, we write it like this."}, {"start": 85.84, "end": 93.5, "text": " We want to minimize j as a function of w and b."}, {"start": 93.5, "end": 99.28, "text": " So now, in order for us to better visualize the cost function j, let's work with a simplified"}, {"start": 99.28, "end": 102.16000000000001, "text": " version of the linear regression model."}, {"start": 102.16000000000001, "end": 108.96000000000001, "text": " We're going to use the model fw of x is w times x."}, {"start": 108.96, "end": 114.11999999999999, "text": " You can think of this as taking the original model on the left and getting rid of the parameter"}, {"start": 114.11999999999999, "end": 118.19999999999999, "text": " b or setting the parameter b equal to zero."}, {"start": 118.19999999999999, "end": 121.33999999999999, "text": " So it just goes away from the equation."}, {"start": 121.33999999999999, "end": 125.16, "text": " So f is now just w times x."}, {"start": 125.16, "end": 132.0, "text": " So you now have just one parameter w and your cost function j looks similar to what it was"}, {"start": 132.0, "end": 139.64, "text": " before, taking the difference and squaring it, except that now f is equal to w times"}, {"start": 139.64, "end": 145.68, "text": " xi and j is now a function of just w."}, {"start": 145.68, "end": 150.08, "text": " And the goal becomes a little bit different as well because you have just one parameter"}, {"start": 150.08, "end": 152.6, "text": " w, not w and b."}, {"start": 152.6, "end": 160.12, "text": " So with this simplified model, the goal is to find a value for w that minimizes j of"}, {"start": 160.12, "end": 161.96, "text": " w."}, {"start": 161.96, "end": 168.60000000000002, "text": " To see this visually, what this means is that if b is set to zero, then f defines a line"}, {"start": 168.60000000000002, "end": 170.60000000000002, "text": " that looks like this."}, {"start": 170.60000000000002, "end": 175.92000000000002, "text": " And you see that the line passes through the origin here because when x is zero, well,"}, {"start": 175.92000000000002, "end": 178.48000000000002, "text": " f of x is zero too."}, {"start": 178.48000000000002, "end": 183.34, "text": " Now using this simplified model, let's see how the cost function changes as you choose"}, {"start": 183.34, "end": 187.36, "text": " different values for the parameter w."}, {"start": 187.36, "end": 195.48000000000002, "text": " In particular, let's look at graphs of the model f of x and the cost function j."}, {"start": 195.48000000000002, "end": 202.32000000000002, "text": " I'm going to plot these side by side and you'll be able to see how the two are related."}, {"start": 202.32000000000002, "end": 209.36, "text": " First notice that for f subscript w, when the parameter w is fixed, that is, is always"}, {"start": 209.36, "end": 217.28, "text": " a constant value, then f w is only a function of x, which means that the estimated value"}, {"start": 217.28, "end": 223.08, "text": " of y depends on the value of the input x."}, {"start": 223.08, "end": 231.64000000000001, "text": " In contrast, looking to the right, the cost function j is a function of w, where w controls"}, {"start": 231.64, "end": 239.95999999999998, "text": " the slope of the line defined by f w, so the cost defined by j depends on a parameter,"}, {"start": 239.95999999999998, "end": 244.0, "text": " in this case, the parameter w."}, {"start": 244.0, "end": 251.82, "text": " So let's go ahead and plot these functions f w of x and j of w side by side so you can"}, {"start": 251.82, "end": 255.83999999999997, "text": " see how they are related."}, {"start": 255.84, "end": 262.68, "text": " We'll start to the model that is the function f w of x on the left."}, {"start": 262.68, "end": 269.96, "text": " Here the input feature x is on the horizontal axis and the output value y is on the vertical"}, {"start": 269.96, "end": 270.96, "text": " axis."}, {"start": 270.96, "end": 278.4, "text": " Here's a plot of three points representing the trading set at positions 1 1, 2 2, and"}, {"start": 278.4, "end": 280.76, "text": " 3 3."}, {"start": 280.76, "end": 285.04, "text": " Let's pick a value for w, say w is 1."}, {"start": 285.04, "end": 293.68, "text": " So for this choice of w, the function f w looks like this straight line with a slope"}, {"start": 293.68, "end": 295.52000000000004, "text": " of 1."}, {"start": 295.52000000000004, "end": 303.62, "text": " Now what you can do next is calculate the cost j when w equals 1."}, {"start": 303.62, "end": 308.40000000000003, "text": " So you may recall that the cost function is defined as follows, it's the squared error"}, {"start": 308.40000000000003, "end": 310.16, "text": " cost function."}, {"start": 310.16, "end": 319.52000000000004, "text": " So if you substitute f w of x i with w times x i, the cost function looks like this, where"}, {"start": 319.52000000000004, "end": 325.24, "text": " this expression is now w times x i minus y i."}, {"start": 325.24, "end": 331.06, "text": " So for this value of w, it turns out that the error term inside the cost function, this"}, {"start": 331.06, "end": 337.90000000000003, "text": " w times x i minus y i is equal to zero for each of the three data points."}, {"start": 337.9, "end": 342.35999999999996, "text": " Notice for this data set, when x is 1, then y is 1."}, {"start": 342.35999999999996, "end": 347.08, "text": " When w is also 1, then f of x equals 1."}, {"start": 347.08, "end": 353.56, "text": " So f of x equals y for this first training example, and the difference is zero."}, {"start": 353.56, "end": 358.0, "text": " Plugging this into the cost function j, you get zero squared."}, {"start": 358.0, "end": 365.03999999999996, "text": " Similarly, when x is 2, then y is 2, and f of x is also 2."}, {"start": 365.04, "end": 369.32, "text": " So again, f of x equals y for the second training example."}, {"start": 369.32, "end": 375.32, "text": " In the cost function, the squared error for the second example is also zero squared."}, {"start": 375.32, "end": 383.08000000000004, "text": " Finally, when x is 3, then y is 3, and f of 3 is also 3."}, {"start": 383.08000000000004, "end": 387.56, "text": " In the cost function, the third squared error term is also zero squared."}, {"start": 387.56, "end": 395.48, "text": " So for all three examples in this training set, f of x i equals y i for each training"}, {"start": 395.48, "end": 397.12, "text": " example i."}, {"start": 397.12, "end": 403.4, "text": " So f of x i minus y i is zero."}, {"start": 403.4, "end": 412.84000000000003, "text": " So for this particular data set, when w is 1, then the cost j is equal to zero."}, {"start": 412.84, "end": 418.4, "text": " Now what you can do on the right is plot the cost function j."}, {"start": 418.4, "end": 424.96, "text": " And notice that because the cost function is a function of the parameter w, the horizontal"}, {"start": 424.96, "end": 429.26, "text": " axis is now labeled w and not x."}, {"start": 429.26, "end": 435.59999999999997, "text": " And the vertical axis is now j and not y."}, {"start": 435.59999999999997, "end": 440.64, "text": " So you have j of 1 equals to zero."}, {"start": 440.64, "end": 447.21999999999997, "text": " In other words, when w equals 1, j of w is zero."}, {"start": 447.21999999999997, "end": 450.91999999999996, "text": " So let me go ahead and plot that."}, {"start": 450.91999999999996, "end": 456.4, "text": " Now let's look at how f and j change for different values of w."}, {"start": 456.4, "end": 458.76, "text": " w can take on a range of values, right?"}, {"start": 458.76, "end": 466.14, "text": " So w can take on negative values, w can be zero, and it can take on positive values too."}, {"start": 466.14, "end": 470.84, "text": " So what if w is equal to 0.5 instead of 1?"}, {"start": 470.84, "end": 474.0, "text": " What would these graphs look like then?"}, {"start": 474.0, "end": 475.59999999999997, "text": " Let's go ahead and plot that."}, {"start": 475.59999999999997, "end": 479.44, "text": " So let's set w to be equal to 0.5."}, {"start": 479.44, "end": 486.28, "text": " And in this case, the function f of x now looks like this, is aligned with a slope equal"}, {"start": 486.28, "end": 489.59999999999997, "text": " to 0.5."}, {"start": 489.6, "end": 496.88, "text": " And let's also compute the cost j when w is 0.5."}, {"start": 496.88, "end": 500.96000000000004, "text": " Recall that the cost function is measuring the squared error or difference between the"}, {"start": 500.96000000000004, "end": 512.2, "text": " estimated value that is y hat i, which is f of x i, and the true value that is y i for"}, {"start": 512.2, "end": 514.5600000000001, "text": " each example i."}, {"start": 514.56, "end": 520.56, "text": " So visually you can see that the error or difference is equal to the height of this"}, {"start": 520.56, "end": 527.92, "text": " vertical line here when x is equal to 1, because this little line is the gap between the actual"}, {"start": 527.92, "end": 535.52, "text": " value of y and the value that the function f predicted, which is a bit further down here."}, {"start": 535.52, "end": 545.36, "text": " So for this first example, when x is 1, f of x is 0.5, so the squared error on the first"}, {"start": 545.36, "end": 551.1999999999999, "text": " example is 0.5 minus 1 squared."}, {"start": 551.1999999999999, "end": 555.96, "text": " Remember the cost function will sum over all the training examples in the training set."}, {"start": 555.96, "end": 559.68, "text": " So let's go on to the second training example."}, {"start": 559.68, "end": 570.0799999999999, "text": " When x is 2, the model is predicting f of x is 1, and the actual value of y is 2."}, {"start": 570.0799999999999, "end": 575.28, "text": " So the error for the second example is equal to the height of this little line segment"}, {"start": 575.28, "end": 582.5999999999999, "text": " here, and the squared error is the square of the length of this line segment, so you"}, {"start": 582.5999999999999, "end": 586.8399999999999, "text": " get 1 minus 2 squared."}, {"start": 586.84, "end": 593.4, "text": " Let's do the third example. Repeating this process, the error here, also shown by this"}, {"start": 593.4, "end": 599.9200000000001, "text": " line segment, is 1.5 minus 3 squared."}, {"start": 599.9200000000001, "end": 606.24, "text": " Next we sum up all of these terms, which turns out to be equal to 3.5."}, {"start": 606.24, "end": 615.5600000000001, "text": " Then we multiply this term by 1 over 2m, where m is the number of training examples."}, {"start": 615.56, "end": 624.56, "text": " Since there are three training examples, m equals 3, so this is equal to 1 over 2 times"}, {"start": 624.56, "end": 629.9799999999999, "text": " 3, where this m here is 3."}, {"start": 629.9799999999999, "end": 638.3199999999999, "text": " If we work out the math, this turns out to be 3.5 divided by 6, so the cost j is about"}, {"start": 638.3199999999999, "end": 640.8, "text": " 0.58."}, {"start": 640.8, "end": 645.4399999999999, "text": " Let's go ahead and plot that over there on the right."}, {"start": 645.44, "end": 648.72, "text": " Now let's try one more value for w."}, {"start": 648.72, "end": 651.44, "text": " How about if w equals 0?"}, {"start": 651.44, "end": 657.6400000000001, "text": " What do the graphs for f and j look like when w is equal to 0?"}, {"start": 657.6400000000001, "end": 664.5600000000001, "text": " It turns out that if w is equal to 0, then f of x is just this horizontal line that is"}, {"start": 664.5600000000001, "end": 670.6800000000001, "text": " exactly on the x-axis, and so the error for each example is a line that goes from each"}, {"start": 670.68, "end": 677.3199999999999, "text": " point down to the horizontal line that represents f of x equals 0."}, {"start": 677.3199999999999, "end": 687.12, "text": " So the cost j when w equals 0 is 1 over 2m times the quantity 1 squared plus 2 squared"}, {"start": 687.12, "end": 696.54, "text": " plus 3 squared, and that's equal to 1 over 6 times 14, which is about 2.33."}, {"start": 696.54, "end": 705.36, "text": " So let's plot this point where w is 0 and j of 0 is 2.33 over here."}, {"start": 705.36, "end": 708.52, "text": " And you can keep doing this for other values of w."}, {"start": 708.52, "end": 717.3199999999999, "text": " Since w can be any number, it can also be a negative value, so if w is negative 0.5,"}, {"start": 717.3199999999999, "end": 723.12, "text": " then the line f is a downward sloping line like this."}, {"start": 723.12, "end": 729.84, "text": " It turns out that when w is negative 0.5, then you end up with an even higher cost around"}, {"start": 729.84, "end": 734.96, "text": " 5.25, which is this point up here."}, {"start": 734.96, "end": 740.44, "text": " And you can continue computing the cost function for different values of w and so on and plot"}, {"start": 740.44, "end": 742.04, "text": " these, right?"}, {"start": 742.04, "end": 747.2, "text": " So it turns out that by computing a range of values, you can slowly trace out what the"}, {"start": 747.2, "end": 749.8, "text": " cost function j looks like."}, {"start": 749.8, "end": 752.6800000000001, "text": " And that's what j is."}, {"start": 752.68, "end": 761.2399999999999, "text": " To recap, each value of parameter w corresponds to a different straight line fit, f of x,"}, {"start": 761.2399999999999, "end": 763.8, "text": " on the graph to the left."}, {"start": 763.8, "end": 771.12, "text": " And for the given training set, that choice for a value of w corresponds to a single point,"}, {"start": 771.12, "end": 774.3, "text": " a single point, on the graph on the right."}, {"start": 774.3, "end": 780.0799999999999, "text": " Because for each value of w, you can calculate a cost j of w."}, {"start": 780.08, "end": 788.32, "text": " For example, when w equals 1, this corresponds to this straight line fit through the data."}, {"start": 788.32, "end": 795.9200000000001, "text": " And it also corresponds to this point on the graph of j, where w equals 1 and the cost"}, {"start": 795.9200000000001, "end": 799.2800000000001, "text": " j of 1 equals 0."}, {"start": 799.2800000000001, "end": 806.48, "text": " Whereas when w equals 0.5, this gives you this line, which has a smaller slope."}, {"start": 806.48, "end": 812.32, "text": " And this line, in combination with the training set, corresponds to this point on the cost"}, {"start": 812.32, "end": 817.28, "text": " function graph at w equals 0.5."}, {"start": 817.28, "end": 822.84, "text": " So for each value of w, you wind up with a different line and its corresponding cost"}, {"start": 822.84, "end": 825.16, "text": " j of w."}, {"start": 825.16, "end": 829.36, "text": " And you can use these points to trace out this plot on the right."}, {"start": 829.36, "end": 835.48, "text": " Given this, how can you choose the value of w that results in the function f fitting the"}, {"start": 835.48, "end": 836.76, "text": " data well?"}, {"start": 836.76, "end": 843.28, "text": " Well, as you can imagine, choosing a value of w that causes j of w to be as small as"}, {"start": 843.28, "end": 846.44, "text": " possible seems like a good bet."}, {"start": 846.44, "end": 851.44, "text": " J is the cost function that measures how big the squared errors are."}, {"start": 851.44, "end": 856.64, "text": " So choosing w that minimizes these squared errors, makes them as small as possible, would"}, {"start": 856.64, "end": 858.52, "text": " give us a good model."}, {"start": 858.52, "end": 863.8000000000001, "text": " In this example, if you were to choose the value of w that results in the smallest possible"}, {"start": 863.8, "end": 869.4399999999999, "text": " value of j of w, you'd end up picking w equals 1."}, {"start": 869.4399999999999, "end": 872.16, "text": " And as you can see, that's actually a pretty good choice."}, {"start": 872.16, "end": 877.0799999999999, "text": " This results in a line that fits the training data very well."}, {"start": 877.0799999999999, "end": 884.0799999999999, "text": " So that's how in linear regression, you use the cost function to find the value of w that"}, {"start": 884.0799999999999, "end": 886.76, "text": " minimizes j."}, {"start": 886.76, "end": 893.76, "text": " Or in the more general case, when we had parameters w and b rather than just w, you find the values"}, {"start": 893.76, "end": 897.3199999999999, "text": " of w and b that minimize j."}, {"start": 897.3199999999999, "end": 906.0, "text": " So to summarize, you saw plots of both f and j and work through how the two are related."}, {"start": 906.0, "end": 911.04, "text": " As you vary w or vary w and b, you end up with different straight lines."}, {"start": 911.04, "end": 916.56, "text": " And when that straight line passes close to data, the cost j is small."}, {"start": 916.56, "end": 922.56, "text": " So the goal of linear regression is to find the parameters w or w and b that results in"}, {"start": 922.56, "end": 926.92, "text": " the smallest possible value for the cost function j."}, {"start": 926.92, "end": 933.1199999999999, "text": " Now in this video, we worked through our example with a simplified problem using only w."}, {"start": 933.1199999999999, "end": 938.2399999999999, "text": " In the next video, let's visualize what the cost function looks like for the full version"}, {"start": 938.2399999999999, "end": 942.04, "text": " of linear regression using both w and b."}, {"start": 942.04, "end": 944.8, "text": " And you see some cool 3D plots."}, {"start": 944.8, "end": 954.4799999999999, "text": " Let's go to the next video."}]