Linear regression Linear Regression

Source: Internet
Author: User

hypothesis function

Suppose we have a set of house size and price of the relationship between the data, and the area as the horizontal axis, the price as the ordinate to draw it out, with such a data, suppose to give you a house area, how to predict the price of the house?

        

A straightforward approach is to use training data to fit a straight line out, in linear regression we call hypothesis function, where there is only one eigenvalue (i.e. house price), so hypothesis function is $ $h _{\theta} (x) =\ Theta_{0} x_{0} + \theta_{1} x_{1}$$ where $x_{0}=1$,

When there are multiple eigenvalues, the hypothesis function is: $ $h _{theta} (x) = \sum_{i=0}^n \theta_i x_i = \theta^t x$$

So now given a set of training data, how do we choose $\theta$?

Cost function

In order to solve the above mentioned choice $\theta$ problem, our practice is to make $h (x) $ and $y$ values closest, that is, we do not have a group of data will have a predictive value $h (x) $ (through the hypothesis function solution) and the real value Y, What we need to do is to minimize the difference between the predicted value of all sample data and the real value, so define the following cost function: $ $J (\theta) = \frac{1}{2} \sum_{i=1}^m (H_{\theta} (x^{(i)})-y^{(i)}) ^2$$

This cost function is actually a regression model of least squares. Here is a description of the characteristic value:

The cost function is drawn in the following form:

The solution of Gradient gradient descent method

We want to choose $\theta$ to make the $j (\theta) $ minimum, here we use the gradient descent method to solve. $J (\theta) $ is a function of $\theta$ as a variable, so it is actually the $\theta$, then the gradient is actually a vector consisting of the partial derivative of each variable, the size of the vector represents the value of the function change, the direction of the vector indicates the direction of the function value falling fastest.

The gradient descent method is described as follows:

    • Start pick $\theta$ Initial value $ (\tehta_0, \theta_1, ..., \theta_n) ^t$
    • Change the value of $theta$ each time to reduce $j (\theta) $, knowing we get a minimum value

$\theta$ Each Update method is as follows: $$\theta_j: = \theta_j-\alpha \frac{\partial}{\partial\theta_j}j (\theta) $$

Here $\alpha$ is the learning rate (learning rates), in order to achieve this algorithm, we need to ask $\frac{\partial}{\partial\theta_j}$:

So the rules for updating are as follows:

Gradient descent in the form of effects:

The last line drawn:

Using MATLAB to achieve gradient descent method

The training sample form is as follows:

The

Linear regression Linear Regression

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.