Linear regression
The first thing to understand is what is regression. The goal of regression is to predict the target value of another numerical data by using several known data.
Assuming that the characteristics and results satisfy a linear relationship , that is, to satisfy a formula H (x), the independent variable of the formula is the known data x, the function value h (x) is the target value to be predicted. This formula is called regression equation, and the process of getting this equation is called regression.
Suppose the house area and the number of bedrooms is an independent variable x, using X1 to represent the housing area, x2 the number of bedrooms; the price of a house is the dependent variable y, and we use H (x) to represent Y. Suppose the size of the house, the number of bedrooms, and the price of the house are linear.
They meet the formula
The θ in the above formula is a parameter, also known as a weight, which can be understood as the effect of X1 and X2 on H (x). A slight change to this formula is
Both θ and X can be seen as vectors, and n is the number of features.
If we predict H (x) based on this formula, the X in the formula is what we know (the eigenvalues in the sample), but the value of θ is not known , so long as we solve the value of theta, we can make predictions based on this formula.
Minimum mean method (Least Mean squares)
Before introducing the LMS, let's look at what the concept of loss function is.
What we're going to do is to select the optimal theta based on our training set and let H (x) as close to the real value as possible in our training set. The difference between H (x) and real values, we define a function to describe the gap, which is called the loss function , and the expression is as follows:
The loss function here is the well-known least squares loss function, which also involves a concept called least squares, which is no longer unfolding. We want to select the optimal θ so that H (x) is the most recent real value. This problem is converted to the optimal θ, and the loss function J (θ) takes the minimum value. (There are many other types of loss functions)
So how to solve the problem after the transformation? This again involves a concept: LMS and gradient descent (Radient descent).
LMS is the theoretical basis for finding the H (x) regression function, and the method of finding the best parameter by minimizing the mean square error .
Gradient Descent
We want to solve the minimum theta value of J (θ), the approximate idea of the gradient descent algorithm is that we give theta an initialized value first, then change the θ value to make j (θ) smaller, and constantly change the process of θ to make j (θ) smaller until J (θ) is approximately equal to the minimum value.
First we give Theta an initial value, and then we update the value of θ in the direction where J (θ) changes the most, so iterate. The formula is as follows:
α in the formula is called step (learning rate), which controls the amplitude of the change in the direction that θ is smaller each time to J (θ). The bias of the J (θ) to θ indicates the direction in which J (θ) changes most. Because of the minimum value, the gradient direction is the inverse direction of the partial derivative.
- α is too small to converge too slowly, too large to be overshoot the minimum.
- The closer to the minimum, the slower the descent rate
- Convergence: Iteration ends when the difference between the current two iterations is less than a certain value
To solve this bias, the process is as follows:
Then the iterative formula for θ becomes:
The expression above applies only when the number of samples is only one, so how do I calculate the predictive function when I have a sample of M values? Batch gradient descent algorithm and stochastic gradient descent algorithm
Batch gradient descent algorithm
The formula for calculating the parameters of a single sample in the previous section to process multiple samples is expressed as follows:
This new expression requires all training set data for each step of the calculation, so it is called batch gradient descent (batch gradient descent).
Note that the gradient descent may get local optimality , but in the optimization problem we have proved that linear regression has only one of the most advantages, because the loss function J (θ) is a two-time convex function and does not produce a local optimal condition. (Assuming the learning step α is not particularly large)
The algorithm execution process of batch gradient descent is as follows:
We carefully look at the mathematical expression of the batch gradient drop, each iteration of the data set to calculate the sum of the sample, the computational amount will be very large, especially the training data set is particularly large case. Is there a method that has less computational capacity and a good effect? Yes! This is: Random gradient descent (Stochastic Gradient descent, SGD)
Stochastic gradient descent algorithm
Random gradient descent in the quickest direction of calculation, random selection of a data to calculate, instead of scanning all the training data set, thus speeding up the iteration speed.
The random gradient descent is not convergent along the fastest descending direction of J (θ), but rather the way of oscillation tends to be minimal.
The random gradient descent expression is as follows:
The execution process is as follows:
The batch gradient descent and the random gradient descent are compared on three-dimensional graphs as follows:
Summarize:
First article of the year, refueling
Reference:
Http://mp.weixin.qq.com/s/7WlGN8JxfSmpJ8K_EyvgQA
Http://m.elecfans.com/article/587673.html
Supervised learning: Stochastic gradient descent algorithm (SGD) and batch gradient descent algorithm (BGD)