# Linear Regression

![Source: Wikipedia ’Linear Regression’](https://2327526407-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LvBP1svpACTB1R1x_U4%2F-Lw5TMq46bZGMFbfk1mp%2F-Lw6knp2_7o5GuRQ3uYi%2Fimage.png?alt=media\&token=3bb50fc7-fa27-4484-a430-1370caaf9e62)

Linear regression is an algorithm (belonging to both statistics and machine learning) that models the relationship between two or more variables by fitting a linear equation to a dataset.  Independent variables are the features (input data) and dependent variables are the target (what you are trying to predict). &#x20;

The technique is very simple and can be represented by this familiar equation:

![](https://2327526407-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LvBP1svpACTB1R1x_U4%2F-Lw5TMq46bZGMFbfk1mp%2F-Lw6reDg0_e8LuhuCJSF%2Fimage.png?alt=media\&token=3ec27dbc-9f13-4e01-afff-89b115d2be32)

However, this is typically written slightly differently in machine learning:

![](https://2327526407-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LvBP1svpACTB1R1x_U4%2F-Lw5TMq46bZGMFbfk1mp%2F-Lw6utnYPHwHu1RxZtdz%2Fimage.png?alt=media\&token=23440bba-b12f-454d-91f8-fd50d5ea2691)

Or for a more advanced model with multiple features:

![](https://2327526407-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LvBP1svpACTB1R1x_U4%2F-Lw5TMq46bZGMFbfk1mp%2F-Lw6v80B-XE72FhKq2YQ%2Fimage.png?alt=media\&token=a7f1cabf-f4c0-4cec-96dc-1ae0feda8494)

Where:

* *y* is the predicted label
* *b* is the bias (the intercept)
* *w1* is the coefficient or weight of the first feature (weight = *m* or slope)
* *x1* is a feature (an input)<br>

Like [logistic regression](https://machine-learning.paperspace.com/wiki/logistic-regression), [gradient descent](https://machine-learning.paperspace.com/wiki/gradient-descent) is typically used to optimize the values of the coefficients (each input value or column) by iteratively minimizing the loss of the model during training. &#x20;

**Mean squared error** and **mean absolute error** are common [loss functions](https://machine-learning.paperspace.com/accuracy-and-loss#loss) for linear regression.

**Regularization** is a technique used to prevent [overfitting ](https://machine-learning.paperspace.com/wiki/overfitting-vs-underfitting)by penalizing signals that provide too much explanatory power to a single feature. &#x20;

### Linear vs Logistic Regression

**Linear regression** predictions are continuous (e.g. test scores from 0-100).

**Logistic regression** predictions classify items where only specific values or classes are allowed (e.g. binary classification or multiclass classification). The model provides a probability score (confidence) with each prediction.
