# Linear regression

> Canonical: https://skillalmanac.com/glossary/linear-regression | Last verified: 2026-11-24 | Index status: index-eligible

Linear regression is a supervised method that predicts a number as a weighted sum of input features plus a constant, with the weights chosen so the predictions fit the training data as closely as possible.

Also called: linear regression machine learning, linear regression model, linear regression algorithm, OLS regression.

## In plain language

Linear regression predicts a number by adding weighted features and a constant. With one unchanged input feature, its predictions form a straight line. With several features it uses a weighted combination; supplying squared or other transformed features can let that combination describe a curve in the original input. Outliers and poorly chosen features can affect the fit, so evaluate predictions on data excluded from fitting.

## Technical definition

A linear regression model predicts y_hat = w0 + w1*x1 + ... + wp*xp. In the Google Machine Learning Crash Course the weight plays the role of the slope and the bias the role of the y-intercept, both calculated during training. Ordinary least squares, as implemented by scikit-learn's LinearRegression, fits the coefficients to minimize the residual sum of squares between observed and predicted targets. Near linear dependence among columns of the design matrix can make coefficient estimates unstable. Linear independence of columns is not the same as statistical independence of input variables. Regularized variants such as ridge and lasso are covered in the same guide.

## How it shows up when you use agents

Linear regression is one [supervised learning](/glossary/supervised-learning) baseline for predicting a number that an agent can build when you ask Claude Code, Codex or Cursor to model a column in a CSV. It also connects to modern training: a [loss function](/glossary/loss-function) measures the gap between predictions and targets, and [gradient descent](/glossary/gradient-descent) is one way to reduce it, although least squares can also be solved directly.

The catalogue has no skill that trains models, so the examples cover the work around one. A common failure is reading too much into a fitted line. A strong fit on training data says little about new data, correlated input columns can make the coefficients unstable, and an unsuitable feature representation can miss a curved relationship. Ask the agent to profile the data first, report error on held-out rows, and plot the residuals. A next action is to compare it with a more flexible model on the same split.

## Worked example (illustrative)

Choose the toy model y_hat = 1 + 2x + 3x². At x = 2 it returns 17. It is linear in its chosen coefficients even though its predictions form a curve as x varies. Its supplied features are x and x². This arithmetic counterexample shows why linear does not mean a straight line in the original input; no coefficients were fitted and no predictive accuracy was measured.

## Common confusions

- **Linear regression versus logistic regression.** Linear regression predicts a number. [Logistic regression](/glossary/logistic-regression) is used for classification into categories, despite the word regression in its name.
- **Linear versus straight line.** The model is linear in its weights. You can feed it transformed features, but what it learns is still a weighted sum.
- **Fit versus cause.** A fitted weight describes a pattern in the data. It does not show that changing the input would change the outcome.
- **Statistics versus machine learning.** The method is the same. In a machine-learning setting, it fits the relationship between features and a label.

## Worked examples in this catalogue

### [data-analysis-eda](https://skillalmanac.com/skills/skill-almanac/data-analysis-eda)

Status: illustrative example from the item's own documentation, not executed for this page.

What you see: A fixed exploratory-analysis procedure and a CSV profiler, with findings kept descriptive, evidenced and caveated.

Why it exercises the concept: The catalogue has no training skills. Profiling a table first shows the column types, gaps and spread that decide whether this method is a sensible choice for the data.

### [split-leakage-check](https://skillalmanac.com/skills/skill-almanac/split-leakage-check)

Status: illustrative example from the item's own documentation, not executed for this page.

What you see: A JSON report that checks train, validation and test files for duplicates, shared groups, time leakage and label leakage.

Why it exercises the concept: The catalogue has no skill that trains this algorithm. This one covers the step that decides whether a score from any trained model can be trusted: whether the test rows were kept apart from the training rows.

### [mock-record-generator](https://skillalmanac.com/skills/skill-almanac/mock-record-generator)

Status: illustrative example from the item's own documentation, not executed for this page.

What you see: Seeded mock records written as CSV or JSON from a JSON field list or a simple TypeScript interface.

Why it exercises the concept: The catalogue has no training skills. Seeded mock rows give you a small, repeatable table to try a scikit-learn example on without touching real data.

## Related terms

- [Supervised learning](https://skillalmanac.com/glossary/supervised-learning.md)
- [Machine learning (ML)](https://skillalmanac.com/glossary/machine-learning.md)
- [Loss function](https://skillalmanac.com/glossary/loss-function.md)
- [Gradient descent](https://skillalmanac.com/glossary/gradient-descent.md)
- [Overfitting](https://skillalmanac.com/glossary/overfitting.md)
- [Logistic regression](https://skillalmanac.com/glossary/logistic-regression.md)

## Sources

- [1.1. Linear Models](https://scikit-learn.org/stable/modules/linear_model.html), scikit-learn (accessed 2026-11-24)
- [What is linear regression?](https://www.ibm.com/think/topics/linear-regression), IBM (accessed 2026-11-24)
- [Linear regression](https://developers.google.com/machine-learning/crash-course/linear-regression), Google for Developers (Machine Learning Crash Course) (accessed 2026-11-24)
- [Preprocessing: polynomial feature construction](https://scikit-learn.org/stable/modules/preprocessing.html#polynomial-features), scikit-learn (accessed 2026-11-24)

Definitions are written by Skill Almanac from the sources above and checked against them on 2026-11-24. [Glossary index](https://skillalmanac.com/glossary.md).
