How does linear regression work?

In simple terms, linear regression tries to fit as many of the data points as possible with a line in two-dimensional space or a plane in three-dimensional space, and so on. It explores the linear relationship between observations and targets and the relationship is represented in a linear equation or weighted sum function. Given a data sample x with n features, x1, x2, …, xn (x represents a feature vector and x = (x1, x2, …, xn)), and weights (also called coefficients) of the linear regression model w (w represents a vector (w1, w2, …, wn)), the target y is expressed as follows:

Also, sometimes, the linear regression model comes with an intercept (also called bias) w0, so the preceding linear relationship becomes as follows:

Doesn't it look familiar? The logistic regression algorithm we learned in Chapter 7, Predicting Online Ads Click-through with Logistic Regression, is just an addition of logistic transformation on top of the linear regression, which maps the continuous weighted sum to 0 (negative) or 1 (positive) class. Similarly, a linear regression model, or specifically, its weight vector w is learned from the training data, with the goal of minimizing the estimation error defined as mean squared error (MSE), which measures the average of squares of difference between the truth and prediction. Give m training samples, (x(1),y(1)), (x(2),y(2)),… (x(i),y(i))…, (x(m),y(m)), the cost function J(w) regarding the weights to be optimized is expressed as follows:

Here,  is the prediction.

Again, we can obtain the optimal w so that J(w) is minimized using gradient descent. The first-order derivative, the gradient ∆w, is derived as follows:

Combined with the gradient and learning rate η, the weight vector w can be updated in each step as follows:

After a substantial number of iterations, the learned w is then used to predict a new sample x' as follows:

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.147.83.176