# 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.


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://machine-learning.paperspace.com/wiki/linear-regression.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
