Five ML Fundamentals: Regression, Forests, Adam, Network Width
Machine LearningModel answerLast updated
Answer five conceptual machine learning questions on regression assumptions, logistic loss, random forest feature sampling, Adam versus SGD, and narrow versus wide networks.
Imagine a technical screen for an applied ML role. You are asked to explain five fundamentals out loud. For each, give a precise answer and justify the reasoning behind it, since follow-up questions will target any hand-waving. Assume standard supervised learning unless stated otherwise. No code is required; light math notation is welcome.
Part 1: Linear regression. Which assumptions underlie linear regression? Which of them are needed for the coefficient estimates to be unbiased or consistent, and which only for trustworthy standard errors, confidence intervals and tests? Why is squared loss the usual choice, and what statistic of the target does its minimizer estimate?
Part 2: Logistic regression. What does logistic regression model? A logarithm shows up in more than one place in its formulation. Identify each place and explain why it is there, including the practical advantages of the log in the training objective.
Part 3: Random forest. What is a random forest and how does it produce a prediction? How is the pool of candidate features chosen at each split, and why does that restriction help generalization?
Part 4: Adam versus SGD. Describe how Adam works, including its per-parameter state, bias correction and update rule. Give at least two strengths and two weaknesses compared with plain SGD, including how it interacts with weight decay.
Part 5: Narrow versus wide networks. Two networks share the same two-layer design, but one has few units per layer and the other has many. Which is more likely to end up stuck in a poor local minimum, and why? What risk comes with the other one, and how would you mitigate it?
Hints
Hint 1
For Part 1, separate what you need for the estimator to be unbiased (linearity in parameters, exogeneity, no perfect collinearity) from what you need for valid inference (homoscedasticity, uncorrelated errors, often normality).
Hint 2
For Part 2, one log is the log-odds (logit) link in the model, and the other is the log-likelihood in the loss. Think about products of probabilities, numerical stability and convexity.
Hint 3
For Parts 3 to 5, tie each answer to a mechanism: variance of an average of correlated predictors, first and second moment estimates with their zero-initialization bias, and the way extra width creates many good directions in the loss landscape.
Model answer
Hard Try it yourself first — then compare your approach, complexity and edge cases.
Part 1: Linear regression
Model: y = Xβ + ε.
Assumptions needed for unbiased and consistent estimates:
- The model is linear in the parameters (features may be transformed).
- Exogeneity: E[ε | X] = 0. Omitted variables correlated with the features, measurement error in the features, or reverse causality break this.
- No perfect multicollinearity, so that XᵀX is invertible.
- Observations are sampled in a way that makes the above meaningful (e.g. i.i.d. or a well-behaved process).
Assumptions needed only for valid inference:
- Homoscedasticity: constant error variance. Without it OLS is still unbiased but the usual standard errors are wrong, so use robust (sandwich) errors.
- Uncorrelated errors, which matters for time series and clustered data.
- Normal errors: not needed for unbiasedness (Gauss-Markov gives BLUE without it). It is added to get exact finite-sample t and F tests. With large n, the CLT makes it largely unnecessary.
Why squared loss:
- Probabilistic: if ε ~ N(0, σ²), maximizing the likelihood is the same as minimizing the sum of squared residuals.
- Statistical: the minimizer of expected squared error is the conditional mean E[y | x], so the model targets the mean.
- Optimization: it is convex and smooth with a closed-form solution (XᵀX)⁻¹Xᵀy, and a gradient that scales with the residual.
- Gauss-Markov: among linear unbiased estimators, OLS has minimum variance.
Caveat: squared loss is sensitive to outliers. Huber or absolute loss (which targets the median) are alternatives.
Part 2: Logistic regression
It models a binary outcome: P(y=1 | x) = σ(wᵀx + b) = 1 / (1 + e^−(wᵀx+b)). Equivalently, the log-odds are linear in the features.
Log #1, the logit link: log(p / (1−p)) = wᵀx + b. A linear score lives on (−∞, ∞) while a probability lives in (0, 1). The log-odds map bridges them, and each coefficient has a clean meaning: a one-unit increase in a feature adds w to the log-odds, i.e. multiplies the odds by e^w.
Log #2, the log-likelihood: the likelihood is a product ∏ pᵢ^yᵢ (1−pᵢ)^(1−yᵢ). Taking logs gives the cross-entropy loss: −Σ [y log p + (1−y) log(1−p)].
Why this is useful beyond "it is the MLE":
- Products of many small probabilities underflow, while sums of logs are stable.
- The gradient simplifies to Xᵀ(p − y), which is the same form as in linear regression, and the loss is convex in w.
- It penalizes confident wrong predictions heavily (loss goes to infinity as p → 0 for y=1), which makes it a proper scoring rule that encourages calibrated probabilities.
- Squared error on a sigmoid output would be non-convex and would have vanishing gradients when the model is confidently wrong.
Assumptions: independent observations, linearity of the log-odds in the features, little multicollinearity. Perfectly separable data makes the MLE diverge, so regularize.
Part 3: Random forest
A random forest is an ensemble of decision trees, each trained on a bootstrap sample of the data. Classification uses majority vote (or averaged probabilities) and regression uses the average.
Two sources of randomness:
- Bootstrap sampling of rows (bagging).
- At every split, only a random subset of
mfeatures is considered (max_featuresin scikit-learn,mtryin R). Common defaults are √p for classification and about p/3 for regression (scikit-learn regression defaults to all features, so tune it).
Why feature subsampling helps: for B trees with individual variance σ² and pairwise correlation ρ, the variance of the average is
ρσ² + (1−ρ)σ² / B.
Adding trees kills only the second term. If one or two features are very strong, every tree splits on them first, so trees are highly correlated and ρσ² dominates. Restricting the candidates forces diversity, lowers ρ, and reduces ensemble variance. The cost is slightly higher bias per tree, so m is a bias-variance knob.
Extras: out-of-bag samples (about 37% of rows per tree) give a free validation estimate. Deep, unpruned trees are fine because averaging controls variance.
Part 4: Adam vs. SGD
State per parameter:
- First moment m, an exponential moving average of gradients (momentum): m ← β₁m + (1−β₁)g.
- Second moment v, an exponential moving average of squared gradients (RMSProp-style adaptive scaling): v ← β₂v + (1−β₂)g².
Bias correction: m and v start at zero, so early estimates are biased toward zero, especially with β₂ ≈ 0.999. Divide by the correction factors: m̂ = m/(1−β₁ᵗ), v̂ = v/(1−β₂ᵗ).
Update: θ ← θ − η · m̂ / (√v̂ + ε). Typical values are β₁=0.9, β₂=0.999, ε=1e−8.
Advantages:
- Per-parameter adaptive step sizes help with sparse or badly scaled gradients.
- It is robust to the choice of learning rate and often converges quickly with little tuning.
- Momentum smooths noisy minibatch gradients.
- It is the standard for transformers and NLP.
Disadvantages:
- Two extra buffers per parameter, so about 3x the optimizer memory of plain SGD.
- It can generalize worse than well-tuned SGD with momentum on some problems, such as image classification, and may converge to sharper minima. There are also known non-convergence cases (motivating AMSGrad).
- Weight decay: adding L2 to the loss gets rescaled by the adaptive denominator, so it is not true decay. Use AdamW, which decouples decay from the gradient step.
- It still needs warmup and scheduling for large models.
Part 5: Narrow vs. wide networks
The narrow network is more likely to get stuck in a poor local minimum. With few units it has limited capacity, and the loss landscape has relatively few good solutions that are isolated from each other, so gradient descent can settle into a bad basin or a poor saddle region.
Why wide is easier: with many units there are exponentially many equivalent solutions (permutation symmetry and redundancy). In high dimensions, most critical points are saddle points rather than bad local minima, and local minima tend to have loss close to the global one. Overparameterized networks can often reach near-zero training loss with many connected paths to it, and the landscape behaves more smoothly (as in the NTK/lazy regime).
Countervailing risk: the wide network can easily fit noise, so it is prone to overfitting. In practice, modern overparameterized nets often still generalize thanks to implicit regularization from SGD, but this is not guaranteed.
Mitigations: weight decay, dropout, early stopping, data augmentation, and a validation set to monitor the gap. For the narrow network, use multiple random restarts, better initialization, and learning rate schedules.
Common mistakes across all parts: claiming normality is needed for OLS unbiasedness, forgetting the logit link, saying forests reduce bias rather than variance, treating Adam's L2 as true weight decay, and answering Part 5 with "more parameters is always better" without mentioning overfitting.