The interview question

“Explain logistic regression, and why it can be a strong classification baseline.”

Logistic regression maps a linear combination of features to a value between zero and one. For binary classification, we interpret that output as an estimated probability of the positive class, subject to validation and calibration.

01. Separate the linear score from the probability

z = w · x + b
p = 1 / (1 + exp(−z))

If z = 0, p = 0.5. If z = 2, p is approximately 0.881. The sigmoid keeps the output bounded, but a bounded output is not automatically a trustworthy probability on new data.

The log-odds, log(p / (1 − p)), equal the linear score. Holding other features fixed, increasing feature j by one unit changes the modeled odds by a factor of exp(wⱼ). This is an association in the fitted model, not a causal effect.

A 0.5 cutoff creates a linear decision boundary in the input feature space. Feature transformations and interactions can make that boundary nonlinear in the original inputs.

02. Work through a small prediction

Imagine a spam model with z = −2 + 1.5 × suspicious_link + 0.4 × repeated_phrase, where both features are binary. A message with both features has z = −0.1 and p ≈ 0.475.

A 0.5 cutoff would not flag it; a 0.3 review threshold would. The model stayed the same—the action policy changed. The coefficients and thresholds here are invented to illustrate the calculation, not recommended spam rules.

Train with binary log loss:

loss = −y log(p) − (1 − y) log(1 − p)

For a positive example, predicting 0.9 gives loss about 0.105; predicting 0.1 gives about 2.303. Confident wrong predictions receive a much larger penalty.

03. Make a useful baseline

Fit preprocessing on training data only. Scale numerical features when needed for optimization and regularization; encode categorical variables with a plan for unseen values. Add L1 or L2 regularization and choose its strength on validation data.

The model is inexpensive to serve, inspect, and compare. It can work well with sparse text features or engineered tabular signals. It will miss interactions that are absent from its feature representation, and a coefficient can be unstable when predictors are highly correlated.

Compare it with a tree-based baseline under the same split and action constraint. Do not discard it solely because a neural model sounds more advanced.

04. Answer the follow-ups

“Is logistic regression always calibrated?”

No. Misspecification, regularization, sampling, and distribution shift can distort probabilities. Inspect held-out calibration, especially if scores drive expected-cost decisions.

“Why not optimize accuracy directly?”

Accuracy depends on a cutoff and gives little optimization guidance when small score changes do not flip labels. Log loss evaluates probabilistic predictions and supports smooth optimization.

Self-review

Can you distinguish the linear score, sigmoid output, training objective, and action threshold? Can you explain one limitation without claiming the model is useless?

Sources & further reading

Google Developers: logistic regression and loss and regularization. Numerical examples are original illustrations.

Read next

When can you trust a probability? ↗

Separate ranking quality from calibration.

Continue your preparation

Choose a connected learning path or browse more ML fundamentals questions. Read our editorial method and attribution policy.