Concepts and worked examples

Linear Models, Logistic Regression, and Margins

Learn how linear models make predictions and how regularization keeps them simple.

A mathematical form with learnable weights

A parametric model starts with a fixed shape and learns its numbers from data. For a linear model, z = w₀ + Σⱼwⱼxⱼ: w₀ is the starting value, xⱼ are the features, and wⱼ say how much each feature matters. Training picks the weights that best meet a chosen score. That score should support the business goal, but it cannot capture every part of it.

For numeric prediction, linear regression uses the score as a predicted value. For binary classification, a linear discriminant uses the sign or threshold of a score to choose a class. Linear means linear in the fitted weights: including a precomputed squared feature or interaction can create nonlinear behavior in original inputs while retaining a linear parameterization.

Coefficient magnitudes depend on units and scaling. Even after standardization, they are not universal importance measures: correlated predictors, regularization, and representation affect their values. An association between a coefficient and an outcome does not establish that changing the feature will cause the predicted change.

Choose a loss that matches the output

A loss assigns a penalty to a prediction for one observation; an empirical objective aggregates losses, often adding a complexity penalty. With residual e = y − ŷ, absolute error is |e|, not the signed difference. Squared error is e² and gives extreme residuals greater influence.

Common losses and their purposes
LossDefinitionInterpretation
Absolute error|y − ŷ|Numeric error magnitude; conditional medians minimize expected absolute loss.
Squared error(y − ŷ)²Least squares; conditional means minimize expected squared loss.
Zero-one loss0 if correct, 1 otherwiseCounts classification mistakes without measuring probability confidence.
Binary log-loss−[y ln(p) + (1 − y) ln(1 − p)]Evaluates probability predictions for labels zero and one.
Hinge lossmax(0, 1 − yz)Penalizes insufficient signed margin for labels minus one and plus one.

Mean absolute error averages absolute losses; MSE averages squared losses; RMSE takes the square root of MSE to return to target units. Outliers and erroneous measurements can strongly influence least squares. Robust alternatives and careful data checks may be more appropriate than silently deleting large legitimate outcomes.

From a linear score to a probability

Ordinary linear scores are unbounded and therefore are not generally valid probabilities. Logistic regression models log-odds linearly, then applies the sigmoid. Although named regression, binary logistic regression estimates the probability of a categorical event.

odds = p/(1 − p)
ln[p/(1 − p)] = z = w₀ + Σⱼ wⱼxⱼ
p = 1/(1 + exp(−z))

Odds are one at p = 0.5 and nine at p = 0.9. A one-unit feature increase multiplies modeled odds by exp(wⱼ), holding other features fixed, not probability by that factor. Fitting commonly minimizes log-loss, equivalent to maximizing the conditional Bernoulli likelihood. A threshold of 0.5 is a choice, not a requirement; costs and capacity can justify another threshold.

Worked example: a renewal score

Suppose z = −2 + 0.5x, where x counts completed onboarding steps. At x = 6, z = 1, odds are exp(1) ≈ 2.718, and renewal probability is 1/(1 + exp(−1)) ≈ 0.731. One additional step multiplies modeled odds by exp(0.5) ≈ 1.649. This does not demonstrate that forcing an extra step causally improves renewal.

If the observed renewal label is one, log-loss is −ln(0.731) ≈ 0.313; if it is zero, loss is −ln(0.269) ≈ 1.313. A model predicting 0.99 for an outcome that is actually zero receives loss −ln(0.01) ≈ 4.605. Confident mistakes are costly. Probability quality still needs held-out assessment and calibration checks.

SVMs and the soft margin

A linear support vector machine seeks a separating decision boundary with a large margin while allowing penalties for difficult observations. In a common normalization, boundary z = 0 lies between margin boundaries z = −1 and z = +1; their geometric separation is 2/‖w‖. A soft-margin objective combines ½‖w‖² with C times the sum of hinge losses. Larger C emphasizes avoiding training violations relative to widening the margin.

Important clarification: hinge loss is positive even for correctly classified observations inside the margin. For y = +1, score z = 0.4 predicts the correct class but incurs loss 0.6. Scores 1.2 and −0.3 incur losses zero and 1.3 respectively. The relevant quantity is the signed score yz, not simply whether the prediction crosses the decision boundary.

Neither logistic regression nor a soft-margin SVM guarantees perfect separation. Overlapping classes, noise, and inadequate features can make perfect separation impossible. With completely separable data, unregularized logistic maximum-likelihood coefficients can grow without a finite optimum. An SVM score is not automatically a probability; probability conversion requires additional fitted calibration.

Regularization and business interpretation

Regularization balances fit against complexity: minimize mean loss + λR(w). L2 uses squared weights and shrinks coefficients; L1 uses absolute weights and can set some to zero. Scaling affects these penalties. Tune the penalty and all preprocessing using validation, not final-test feedback. Evaluate costs, errors, and stability as well as interpretability.

Why not optimize classification accuracy alone?

Zero-one loss ignores probability quality and error costs, and is difficult to optimize directly. Log-loss and hinge loss are tractable surrogates with different objectives; evaluate the resulting policy against business needs.

Does a larger coefficient prove greater causal importance?

No. Units, correlations, feature construction, and confounding affect coefficients. Causal claims need identification assumptions or experiments beyond a predictive fit.

Compare tree segmentation and revisit encoding and scaling.

Definition

View in glossary →