Skip to content
IT glossary
Data and MLUpdated December 3, 2026

Linear regression

Линейная регрессия

A model that predicts a number, such as energy use, by adding a starting value and a weighted contribution from each input. It learns those weights from examples with known outcomes.

What linear regression does

Linear regression estimates a numeric outcome, such as monthly electricity use, from one or more inputs called features. With one feature, the fitted model is a straight line. With several features, each adds a contribution to the prediction. This makes the model useful both as a forecasting baseline and as a way to summarize how an outcome varies with its inputs.

How the model is fitted

A model with two features predicts ŷ = b₀ + b₁x₁ + b₂x₂. The intercept b₀ is the prediction when both features are zero, which may not be a meaningful scenario. The slope b₁ tells you how much the prediction changes when x₁ increases by one unit and x₂ stays fixed.

A residual is the observed value minus the fitted value for a training example. Ordinary least squares (OLS) fits the coefficients by minimizing the sum of squared residuals. Squaring prevents positive and negative residuals from canceling each other out, but also makes the fit sensitive to unusually large errors. You can solve OLS with numerical linear algebra, such as QR decomposition; gradient descent is an option, not a requirement.

Worked example

Suppose a building's fitted model is monthly use (kWh) = 500 + 30 × occupied days + 12 × cooling degree days. Cooling degree days measure how far temperatures rise above a reference temperature over the month. For 20 occupied days and 50 cooling degree days, the prediction is 1,700 kWh. If the building actually used 1,850 kWh that month, the residual is +150 kWh: the model underpredicted. The occupancy coefficient is 30 kWh per additional occupied day at the same cooling demand. It describes a relationship in the model, not necessarily the causal effect of opening the building for another day.

Uses and common pitfalls

Try linear regression before a more complex model when predicting a numeric target like cost or energy use. Evaluate it on data it hasn't seen. If you're forecasting future months, hold out later months for evaluation so the fit cannot learn from the future. Mean absolute error (MAE) reports the average size of a prediction error in the target's original units.

The model must be linear in its fitted coefficients, not in its raw inputs: adding x² as a feature lets it fit a curve. Also watch for features that move closely together. Their individual coefficients can be unreliable even when the predictions are useful.

What comes up in interviews

Interviewers often ask you to interpret a slope, explain OLS, or diagnose a residual plot. A curved pattern in residuals versus fitted values suggests the model is missing some structure. A widening spread suggests nonconstant error variance, which matters for conventional OLS standard errors. Normal errors are not required to fit the model.