KatInterview

Loss, Batch Size, Regularization and Tree Depth: ML Core Review

Machine LearningModel answer
MediumModel answerMachine Learningcross-entropysgdregularization

Last updated

Four connected ML fundamentals: why log loss suits sigmoid outputs, how batch size shapes training, how L1 and L2 differ, and how leaf size controls bias and variance in trees.

Four Core Ideas Behind Training Supervised Models

Imagine you are explaining the following to a teammate who knows basic ML vocabulary but wants to understand the reasoning. Give a structured answer to each part.

  1. Choosing a loss for binary labels. A network ends in a sigmoid and predicts the probability of the positive class. Describe the intuition behind binary cross-entropy. Then explain why it is usually preferred over mean squared error for this setup.

  2. Full-batch versus stochastic updates. Compare full-batch gradient descent with stochastic and mini-batch variants. Suppose the training set has 100 million rows. Discuss how picking a batch size of 1, 32, or 10,000 changes convergence speed, memory use, and how well the final model generalizes.

  3. Penalizing weights. Explain how L1 and L2 penalties act differently on the learned weight vector. Name a concrete situation in which L1 is the better choice.

  4. Tree complexity. For a decision tree, what happens to bias and variance as you raise the minimum number of samples a leaf must contain? Then describe what a leaf looks like, and how the tree behaves, if you let it grow until every leaf holds a single sample.

Use math where it clarifies the point (a gradient, a prior, a variance term), and connect each argument to behavior you would see in practice.

Hints

Hint 1

For part 1, write the gradient of each loss with respect to the pre-activation logit z. Remember that the derivative of the sigmoid is p(1 - p), and check what happens when the prediction is confidently wrong.

Hint 2

For part 2, think of the mini-batch gradient as a noisy but unbiased estimate of the full gradient whose variance shrinks like 1/B. Then weigh updates per epoch, hardware utilization, and memory against that noise.

Hint 3

For parts 3 and 4, picture the constraint shapes (diamond versus circle) and the constant versus proportional shrinkage. For trees, ask how many samples are averaged inside each leaf and how much a single point can change the structure.