KatInterview

Choosing Between a Linear Classifier and a Forest on Small Data

Machine LearningModel answer
MediumModel answerMachine Learninglogistic-regressionrandom-forestregularization

Last updated

Discuss when a regularized linear probabilistic classifier beats a bagged tree ensemble on a small binary task, and how it compares with boosting.

You are building a binary classifier on a small labeled dataset (a few hundred to a few thousand rows). The relationship between features and label may contain some non-linear effects. Your team is deciding between a linear probabilistic model and a tree ensemble.

Answer the following as you would in a technical discussion:

  1. What is logistic regression, and what loss function does it minimize? Where does that loss come from, and what can you say about its optimization?
  2. Under what conditions can logistic regression beat a random forest on this kind of problem?
  3. Explain L1 and L2 regularization for logistic regression. How do they differ in their effect on the learned weights?
  4. How would you detect overfitting in a logistic regression model, and what would you do to reduce it?
  5. Compare random forests with gradient boosting in terms of bias, variance, interpretability, and typical use cases.

Give concrete reasoning and trade-offs rather than definitions alone.

Hints

Hint 1

Start from the log-odds being linear in the features, then write the likelihood of Bernoulli labels and take its negative log. Think about whether the resulting surface has one minimum.

Hint 2

For the small-data comparison, count effective parameters and ask which model has more variance. Also consider extrapolation, calibration, sparse high-dimensional inputs, and how a linear model can still capture non-linearity.

Hint 3

For the ensemble comparison, contrast mechanisms: parallel deep trees averaged to cut variance versus sequential shallow trees fit to the remaining error to cut bias. For overfitting, think about train/validation gaps, learning curves, and unstable coefficients.