Regression

Regression estimates a numeric target from features . In the standard linear case, linear models estimate the conditional mean by minimizing residual error; logistic regression uses a similar linear score but changes the target from a continuous value to a class probability and changes the loss from squared error to cross-entropy.

Defining math

Ordinary least squares writes the prediction for a feature vector as

where is the vector of coefficients. Stacking the examples into a design matrix (one row per example) and targets , it chooses to minimize the squared residual:

When is invertible, this has the closed-form solution

Fit is often summarized by the coefficient of determination

where is the observed target, the prediction, and the sample mean. The numerator is the model’s squared residual error and the denominator is the error from always predicting , so is the fraction of variance the model explains beyond that baseline.

Residuals are not just errors; their pattern is a diagnostic. Curvature suggests missing feature engineering, changing variance suggests heteroscedasticity, and large leverage points can dominate the fitted line. Penalized versions such as ridge replace the objective with , connecting regression directly to regularization.

Intuition

OLS projects the target vector onto the column space of the design matrix. The fitted values are the closest points, in Euclidean distance, that the model class can express. If the true signal is mostly linear in the chosen features, this is efficient and transparent; if the signal is nonlinear, OLS gives the best linear shadow, not the underlying mechanism.

Worked example

Fit to five points , whose mean is . The two sums that define compare the fit against the baseline of always predicting the mean:

The fitted line explains 60% of the variance around the mean: the points hug it more tightly than they hug the flat mean line, and is exactly that reduction in squared error.

R-squared compares residuals from the fitted line with deviations from the mean line; here the fit gives R-squared equal to 0.6.

is unitless and always improves as features are added, so pair it with an error in target units. RMSE here is , which can be compared against an operational tolerance rather than only against the mean.

Caveats

OLS coefficients become unstable when features are nearly collinear because is close to singular. Outliers affect squared error strongly. Extrapolation is linear forever, so a plausible fit inside the training range can produce impossible predictions outside it. Report regression with evaluation metrics that match the decision: RMSE punishes large misses, MAE is more robust, and residual plots often reveal failures that aggregate scores hide.

References