ML0184 Logistic Regression vs Random Forest

A hotel-booking team at a travel site like Expedia asks: what are the advantages of logistic regression versus a random forest, and when would you pick each? Cover linearity assumptions, probability calibration, interpretability, and nonlinear feature interactions.

Three-panel scenario card with dashed borders. Panel 1, the task: rank hotel listings by expected revenue, score equals P(book) times commission, across a flagship market with 2.0 million sessions and 48,000 bookings and a new market with 6,200 sessions and 150 bookings, both at a 2.4 percent booking rate. Panel 2, two candidates trained on flagship data only: logistic regression with 40 features and L2, flagship holdout AUC 0.708, and a random forest with 500 full-depth trees, flagship holdout AUC 0.752. Panel 3, open questions: a partner asks how much a 10 percent price cut raises booking odds, the new market has only 150 bookings to train and validate on, and which model goes where, and why.

The Problem: A travel site must rank hotel listings by P(book) times commission in a flagship market with 48,000 bookings and a new market with only 150. The random forest beats logistic regression on flagship holdout AUC, 0.752 to 0.708, yet a partner wants a stated price effect and nobody has decided which model belongs where.

Answer

Logistic regression (LR) models the log-odds of the outcome as a linear function of the features. That makes it low-variance, cheap to serve, well calibrated when fit by log loss, and readable through one odds ratio per feature, but it only sees the nonlinear shapes and interactions you engineer into its inputs. A random forest (RF) averages hundreds of deep, decorrelated trees, so it finds thresholds and feature interactions on its own and usually wins on discrimination once data is plentiful. Its costs are higher variance on small samples, flat extrapolation outside the training range, and probabilities squeezed toward the middle that need recalibration before any expected-value use. Pick LR when positive events are scarce, when the probability itself is consumed downstream, or when someone needs a stated effect size. Pick RF plus isotonic calibration when you have tens of thousands of events, strong interactions, and ranking quality is the metric.

(1) Linear In The Log-Odds: LR assumes each feature shifts the logit by a constant amount per unit, not that features are Gaussian or that probability is linear. Curvature such as diminishing price sensitivity must enter through engineered features like log price, splines, or buckets, and a missed shape becomes systematic bias that more data never fixes.
(2) Interactions For Free Versus By Hand: A forest that splits on lead time and then on price inside each branch has learned a price by lead-time interaction without being told. LR needs an explicit product term for each one, and 40 features already imply 780 candidate pairs.
(3) Calibration: LR fit by log loss with an intercept is calibrated in the large by construction and usually per bucket when well specified. Forest scores are averages of noisy leaf fractions that rarely reach the extremes, so they need Platt scaling or isotonic regression on held-out data.
(4) Interpretability: An LR coefficient is a global effect size, readable as an odds ratio per unit of the feature. A forest needs permutation importance, partial dependence, or SHAP, and its default impurity importance is biased toward high-cardinality features such as hotel ID.
(5) Data Regime: LR estimates one parameter per feature and has low variance, so it usually wins with a few hundred positive events. Forest accuracy keeps climbing with data, so the learning curves cross, typically somewhere in the low thousands of events.

Mathematical Formulation:
\mathrm{logit}\,p(x) = w^\top x + b
p(x) = \sigma(w^\top x + b)
\mathrm{logit}\,p = w_1 x_1 + w_2 x_2 + w_{12} x_1 x_2 + b
\mathcal{L}(w, b) = -\sum_{i=1}^{n} \ell_i + \lambda \|w\|_2^2
\ell_i = y_i \log p_i + (1 - y_i)\log(1 - p_i)
\frac{\partial \mathcal{L}}{\partial b} = \sum_{i=1}^{n} (p_i - y_i) = 0
\mathrm{OR}_j = e^{w_j}
\hat p_{\mathrm{RF}}(x) = \frac{1}{B}\sum_{t=1}^{B} \hat p_t(x)
\mathrm{EV}(x) = \hat p(x)\, c(x)

Where:

  • p(x) is the predicted booking probability for feature vector x, \mathrm{logit}\,p = \log(p/(1-p)) is the log-odds, w the coefficient vector, b the intercept, and \sigma(z) = 1/(1 + e^{-z}) the logistic function.
  • x_1 and x_2 are two features such as log price and lead time; w_{12} is the interaction coefficient LR only gets if you add the product column, while a forest captures it through nested splits.
  • \mathcal{L} is the L2-penalized log loss over n training sessions indexed by i, \ell_i the per-session log-likelihood, y_i \in \{0, 1\} the booking label, p_i = p(x_i), and \lambda \geq 0 the shrinkage strength.
  • The intercept condition holds because b is unpenalized: at the optimum the predicted probabilities sum to the observed bookings, which is calibration in the large.
  • \mathrm{OR}_j is the multiplicative change in booking odds per one-unit increase in feature j, holding the others fixed.
  • \hat p_t(x) is the fraction of bookings in the leaf of tree t that x falls into, averaged over B bootstrapped trees (B = 500 here).
  • \mathrm{EV}(x) is the expected revenue used for ranking and c(x) the listing’s commission, so any distortion in \hat p flows straight into revenue.

The intercept equation is the quiet reason LR is trusted for probabilities. When the logit is correctly specified, the same log-loss fit also makes the model calibrated bucket by bucket, not just on average. A forest has no comparable condition. Each leaf fraction is a noisy estimate, and bagging averages trees that disagree, so scores for genuinely likely or genuinely unlikely bookings are pulled toward the middle of the range. Niculescu-Mizil and Caruana documented this sigmoid-shaped distortion and showed that Platt scaling or isotonic regression on held-out data removes it.

Worked Example:
Listing A truly books with probability 0.10 and pays $30 commission, so its expected revenue is $3.00. Listing B books with probability 0.02 and pays $120, so it is worth $2.40, and A should rank first. A raw forest scores them 0.085 and 0.030, giving 0.085 x 30 = $2.55 for A and 0.030 x 120 = $3.60 for B, so B jumps ahead. A well-specified LR, or the forest after isotonic calibration, returns roughly 0.10 and 0.02 and restores the correct order. AUC is identical in both cases because A still outscores B, which is why AUC cannot detect the miscalibration that just cost revenue.

Two-panel chart. Left: reliability diagram for booking probabilities from 0 to 0.20; logistic regression follows the dashed diagonal while raw random forest scores form a steeper curve that crosses the diagonal near 0.06, with listing A scored 0.085 but booking 10 percent of the time and listing B scored 0.030 but booking 2 percent of the time. Right: holdout AUC against training bookings on a log axis from 100 to 60,000; logistic regression leads at 150 bookings, the curves cross near 900 bookings, and at 48,000 bookings the random forest reaches 0.752 against 0.708 for logistic regression.

Figure 1: (a) Reliability of booking probabilities: logistic regression tracks the diagonal, while raw forest scores are squeezed toward the middle, so listing A scored 0.085 books 10% of the time and listing B scored 0.030 books 2%. (b) Holdout AUC against training bookings: LR leads below roughly 900 bookings and the forest leads above, reaching 0.752 against 0.708 at 48,000. Curves are schematic, shaped after the learning-curve crossover reported by Perlich et al.

The full trade-off on the axes interviewers usually probe:

PropertyLogistic regressionRandom forest
Functional formLinear in log-odds; curvature only through engineered features (log price, splines, buckets)Piecewise-constant, axis-aligned splits; monotone transforms of a feature change nothing
InteractionsAdded by hand; 40 features imply 780 pairwise termsLearned automatically by nested splits (lead time, then price)
CalibrationCalibrated in the large by construction; good per bucket when well specifiedScores squeezed toward the middle; needs isotonic or Platt on held-out data
InterpretabilityOne coefficient per feature, read as an odds ratio; unstable under collinearityPermutation importance, SHAP, partial dependence; impurity importance favors high-cardinality IDs
Small dataFew parameters, low variance; usually wins below about 1,000 eventsDeep trees memorize; needs thousands of events to pay off
ExtrapolationKeeps the fitted slope beyond the training rangeFlat beyond the last split threshold
PreprocessingScaling, one-hot encoding, imputation, collinearity checksLittle: no scaling, robust to outliers and skewed features
Serving costOne dot product, kilobytes of weights500 tree traversals, often hundreds of MB at full depth

Login to view more content
Log in to track your progress

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *