AI Glossary / Deep learning / Intermediate
Least-squares Analysis
Definition
Least-squares analysis estimates model parameters by minimizing the sum of squared residuals: the differences between observed values and the model's fitted values. It is a widely used fitting principle in statistics and machine learning, not a method limited to deep learning or to straight-line models.
What it means
Real measurements rarely lie exactly on a simple line or curve. Least squares supplies a precise rule for choosing a fitted model from the possibilities allowed by its form. A residual is the observed response minus the fitted response for that observation.
Squaring makes positive and negative residuals contribute positively rather than cancel. It also gives larger residuals disproportionately greater influence on the fitting objective. A residual of ten contributes one hundred squared units, while a residual of one contributes one.
The resulting fit is best according to that objective within the chosen model family and dataset. It is not automatically the best explanation, a causal relationship or the best predictor for future conditions.
How it works
Choose the response variable, predictors and model form, then estimate parameters that minimize the squared-residual sum. Ordinary least squares gives each squared residual equal weight. Weighted least squares includes specified weights, often to address differing measurement precision.
Linear least squares means the model is linear in its unknown parameters. A model containing a squared predictor can still be linear in its coefficients. Nonlinear least squares uses a model whose parameters enter nonlinearly and often requires iterative numerical optimization.
After fitting, examine residual patterns and influential observations. Curvature, changing spread or dependence can indicate that the model or uncertainty calculation needs reconsideration. Assumptions used to justify standard errors and intervals go beyond simply finding the minimum.
For prediction, assess performance on data not used to choose and fit the model. Numerical minimization can succeed even when the model extrapolates poorly or the dataset fails to represent future use.
Three practical examples
- A facilities analyst fits a baseline relationship between operating hours and electricity use, then investigates residuals rather than assuming every deviation is waste.
- A manufacturer estimates calibration coefficients linking a sensor reading to reference measurements, considering differing measurement precision.
- An AI team uses squared-error loss for a continuous-value prediction task and compares the result with a simple least-squares baseline on held-out data.
Think of it this way
Think of choosing a line through a scatter of marks by attaching a penalty to each vertical mismatch. Least squares selects the line with the smallest total squared penalty.
The analogy must retain the direction of measurement: ordinary regression residuals are differences in the response direction, not generally the shortest perpendicular distances to the line. If both coordinates contain important measurement errors, a different modeling approach may be appropriate.
Worked example
Fitting a small teaching dataset
Take three invented observations: (x, y) = (0, 1), (1, 2) and (2, 4). Fit y_hat = a + bx with an intercept. The mean x is 1 and the mean y is 7/3.
The slope is the sum of centered cross-products divided by the sum of squared centered x values: 3/2 = 1.5. The intercept is 7/3 − 1.5, or 5/6.
Fitted values are 5/6, 7/3 and 23/6. The residuals are 1/6, −1/3 and 1/6, whose squared sum is 1/6, approximately 0.167. The candidate line y_hat = 1 + 1.5x instead has residuals 0, −0.5 and 0, giving a larger squared sum of 0.25.
The least-squares line therefore fits this criterion better. Three invented points do not establish a dependable real-world forecast, and extending the line far outside x = 0 to 2 would need additional justification.
Illustrative case study
Fictional case: Oakfield Operations uses least squares to predict daily processing time from incoming workload. The fitted line looks plausible, but residuals become increasingly variable on busy days.
The team investigates whether workload mix, queueing and differing measurement precision explain the pattern. It compares a revised model and appropriate uncertainty treatment rather than reporting the same narrow prediction interval at every workload.
One extreme observation is checked against the source record before any decision to exclude it. The team documents the range of conditions represented in training data. The scenario shows that analysis includes diagnostics and interpretation, not just obtaining coefficients from a fitting command.
Common misconceptions and mistakes
- Least squares always fits a straight line. The criterion applies to many model forms.
- Linear means predictors cannot be squared. Statistical linearity concerns how the unknown coefficients enter the model.
- Minimizing residual error proves the assumptions. The optimization and its statistical justification are separate.
- An unusual residual should automatically be deleted. It may reveal a valid event, a measurement problem or a missing feature of the model.
Business use
Least squares is valuable for interpretable baselines, calibration and relationships between measured quantities. Its familiar form can make results easier to explain, but familiarity is not evidence that its assumptions hold.
Connect the loss to the business decision. Squared error penalizes large misses strongly and treats positive and negative errors symmetrically. If underprediction and overprediction have different consequences, another objective or decision rule may be more suitable. Report units, model range, uncertainty and relevant diagnostics alongside the fitted relationship.
People also ask
Does least squares require normally distributed observations?
No. Computing the fit does not require normal observations. Particular inferential results depend on assumptions about errors and the model.
Is minimizing mean squared error different from minimizing its sum?
For a fixed dataset and the same unweighted residuals, dividing by the constant number of observations gives the same minimizer.
Does a low residual sum prove causation?
No. A good descriptive fit does not resolve confounding or establish the effect of intervention.
Check your understanding
Two residuals are +5 and −5. Can their sum of zero be used to claim a perfect least-squares fit?
Answer: No. Their squared contributions are 25 and 25, giving a total of 50. A perfect fit requires every residual to be zero, not merely positive and negative errors canceling.
Related terms
- Residual
- Mean Squared Error
- Weighted least squares
- Nonlinear regression
- Overfitting
- Calibration
- Regression
- influential observation
Learn next
Read residual analysis and weighted least squares. Fit two candidate lines to a small dataset, calculate their squared residual sums and then inspect whether the residuals reveal a pattern that the smaller sum alone does not resolve.
More in Deep learning
- Layer - A layer is a computational component of a neural network that transforms one or more inputs into outputs.
- Layer norm - Layer norm, short for layer normalization, is a neural-network operation that normalizes activation values across specified feature dimensions within an...
- Learning rule - A learning rule is a procedure that specifies how a model changes its adjustable parameters or internal state in response to data or feedback.
- Lernmatrix - The Lernmatrix, German for learning matrix, is an early associative-learning architecture developed by Karl Steinbuch around 1960.
- Liquid State Machine Network - A liquid state machine network is a reservoir-computing architecture that transforms a time-varying input into changing internal activity, commonly in a...
- Manifold Learning - Manifold learning is a family of methods that seek a lower-dimensional representation of data whose structure may be curved or nonlinear within a...
Sources
NIST/SEMATECH, Least Squares: https://www.itl.nist.gov/div898/handbook/pmd/section4/pmd431.htm. Linear Least Squares Regression: https://www.itl.nist.gov/div898/handbook/pmd/section1/pmd141.htm. Weighted Least Squares: https://www.itl.nist.gov/div898/handbook/pmd/section4/pmd432.htm. Regression diagnostics: https://itl.nist.gov/div898/software/dataplot/refman1/auxillar/regrdiag.htm. The source-list category is retained; least squares has wider statistical scope. Numerical data and Oakfield Operations are fictional illustrations.
Previous: Least squares Next: Least squares estimate