First we should look at multiple linear regression. In contrast to univariate linear regression, the function has multiple variable values, so it has multiple parameters, not just one or two.

For example, the following function:

If the function’s parameters θ and variable x are written as vectors, it can be simplified to the following function:


If you want to predict house prices, there are now two variables x1 and X2 that control the price of a house. X1 is the size of the house, in the range of 0 to 2000, x2 is the number of bedrooms in the house, in the range of 0 to 5, so the contour of the cost function looks something like this, a flat oval.

The gradient descent of this function, which is the red line, and you can see that it’s a long and tortuous journey, so it’s going to take us a long time to do the gradient descent. So how can we shorten this time? Let’s start with this diagram. You see this picture, Mom is too lazy, not round at all, how to do? Offer it! (Manual dog head)

It would be easy to make it look like this. How to offer? You certainly can’t do it by hand because you need Feature Scaling. Scaling the variables x1 and x2 to a range, we scale them all to the range -1 to 1. The easiest way to do this is to divide x1 by 2000 (because it ranges from 0 to 2000) and x2 by 5. Now the variables x1 and x2 are all in the range of -1 to 1, but there is a problem. Do you notice that after processing, the data is all positive and not scattered, so we need to use a slightly more complicated method for feature scaling. Data has been processed using Mean normalization:

Where μn is the mean value and Sn is the standard deviation, you can also use the difference between the maximum and minimum value of this variable. And now you can see that you have both positive and negative data, spread out between minus one and one, and you get gradient descent pretty quickly.

Ps. This article is based on the study notes of Ng’s machine learning course. If you want to learn machine learning together, you can follow the wechat public account “SuperFeng”, looking forward to meeting you.