Everybody, welcome to our lecture, walking through the sample data using vector equation Part 2. In this video, I'm going to show you how we'll use normal equations to solve a linear regression problem with a specific example. The example is in a cool coffee shop, in this shop consumer are willing to buy 200 frappuccino per hour at unit price of four dollars for instance. You are given the data set called frappuccino.csv. Use that data set to predict the demand of the frappuccino per hour from the cool coffee store when they are selling the frappuccino at a unit price of six dollars. This is a linear regression problem. Now, let's recall ourselves about our linear normal equations for linear regression. The solution is the transpose A times A raised to the power negative 1, then we inverse times A transpose times Y, and the error is just with the sum of the error square. Now lets one be the data set, so we transform it to a panel data set. Now we don't want this unnamed column. We can drop it using a drop method. Now let's look at the head. It should be gone now, now we don't have that unnamed column anymore. Now we have this four by two matrix. The data set is bigger than this for simplicity, I reduce the data set so that we can easily use our formula. We set our A to be the price column, so A is a price column, and then our Y to be the demand column, so Y the demand will be on the y-axis. There is a reason why I do this because our Y will be equal to A times X, and then the result, if you do Y equal A times X, capital Y, equal this A times X. X has a form where, when X equals this matrix for example, so X is a column matrix, B,1. You'd narrow what is a two by one matrix. For us to be able to multiply A by X, this has to be, m four by two. Two columns, so the multiplication would be possible. You will be taking these rows times columns, this is a column matrix. Row, column. Let's do that. We set our A to be that, and then y is equal this value here, y equal the demand function, the demand of the coffee per hour. How much people are demanding? That's a current data right there. Now we know A, we know where y, we can find this A transpose times A inverse times A transpose times Y. Let's do this first. A transpose times A. A transpose times A is right here. T, capital T means transpose, so A transpose A is this, is a two-by-two matrix. Now we can start the result to a variable, let's call it P1, so P1 equal A transpose times A. Now, we call P to be the inverse of P1, so P equal P1.INV, so that mean inverse. Now we know P1 if you want to look at it you can just one P. Now, we need to find A transpose times Y. We know that's a two by one matrix. Now the Q will be equal to A transpose times Y. Well, so we start this result to Q. Now, our solution adds, is nothing but this P times Q, so I did it step-by-step, instead of doing this whole thing at the same time, I do it step-by-step. I'll compute these and I multiply it together. We call this one P, and then this one Q. We have these, remember our x has two values, is a two by one matrix, so this will be our P, and then this would be the slope of our linear function. In other words, the approximation of this data set will be ordered form with slope which is negative 15.15x plus these, the intercept which is 265.43. Now we can plot our approximate and they draw data set into the same graph. This is how the dashed line is our approximate, that's our model, and then we'll arrive at our true data set. Now, we note our approximation is not far away from the data set. The next one we need to do is to answer the question, what would be the demand when there's change of your price to six dollars per frappuccino. When they change your price to six dollars, this is how much the demand it would drop. The demand will drop to 174.53 frappucino per hour. The next one we need to do is to find the error. All right, so we know this is the approximate for our data point and our data point we know that we need also our y-value, so the error will be our approximate minus the y-value, you square it. The first y value was 200, the second y value was 192, and then 188, 184, and 180. We take the difference of these and then square them and add them, then our sum of sum square of the sum error is equal to 19, which is not too bad. This is the error that we are making while trying to approximate this data set, and our prediction is not far away from the reality if you look at it. This is x equal 5.6. When these point six dollars, you will see it will be below 180. Thanks, everybody. In this video, we learn how to use our normal equation to solve a coffee shop problem, so we set our y value to be the demand and then in a way A to be the price, so follow only the normal equations, we compute the normal equation in the step-by-step. Then finally, we never resolved, and our prediction was not far away from the reality. Thanks, everybody. I will see you in the next video.