Diagnose Bias and Variance Across KNN and Regularized Models
Company: Cargurus
Role: Data Scientist
Category: Machine Learning
Difficulty: medium
Interview Round: Technical Screen
### Prompt
Explain the bias-variance trade-off as a practical model-diagnosis problem.
1. Define bias and variance, explain how they appear in training and validation behavior, and propose remedies for each.
2. For k-nearest neighbors, explain how changing `k` generally changes bias and variance, including the limiting behavior of very small and very large `k`.
3. Compare L1 and L2 regularization: their objectives, geometric or optimization effects, coefficient behavior, assumptions and trade-offs. Explain how regularization strength affects bias and variance and how you would select it without leaking test information.
### Constraints & Assumptions
- Distinguish irreducible noise from reducible prediction error.
- Treat training-versus-validation patterns as evidence, not infallible proof; leakage, shift, label noise, and optimization failures can mimic them.
- For KNN, discuss feature scaling, distance choice, dimensionality, class imbalance, and boundary behavior where relevant.
- For L1/L2, assume standardized numeric features unless explaining why standardization matters.
### Clarifying Questions to Ask
- Is the task regression or classification, and which loss or product metric matters?
- How large and representative is the validation set?
- Are observations independent, grouped, or time ordered?
- Is interpretability or sparse feature selection a requirement?
- Are predictors highly correlated or measured on very different scales?
### Part 1: Diagnose Bias and Variance
Explain the conceptual decomposition, observable symptoms, and a disciplined experiment to distinguish underfitting from overfitting and other failure modes.
#### Hints
Learning curves across both sample size and model capacity are more informative than one training-validation score pair.
#### What This Part Should Cover
```premium-lock What This Part Should Cover
```
### Part 2: Analyze KNN
Explain how neighborhood size controls smoothness and sensitivity. Address why the textbook monotonic story can be disrupted in real data.
#### Hints
Think about how one changed training point affects a prediction when `k=1` versus when many neighbors vote or average.
#### What This Part Should Cover
```premium-lock What This Part Should Cover
```
### Part 3: Compare L1 and L2
State the penalized objectives and explain sparsity, shrinkage, correlated predictors, optimization, and selection of the regularization parameter.
#### Hints
The different shapes of the penalty constraints help explain why L1 often lands on zero coefficients while L2 usually does not.
#### What This Part Should Cover
```premium-lock What This Part Should Cover
```
### What a Strong Answer Covers
```premium-lock What a Strong Answer Covers
```
### Follow-up Questions
1. Can a model have both high bias and high variance?
2. What happens to KNN as dimensionality grows?
3. Why can L1 select an unstable member of a correlated feature group?
4. How does elastic net address limitations of pure L1 and pure L2?
5. How would distribution shift alter your diagnosis from learning curves?
Quick Answer: Sharpen your ability to diagnose bias and variance from learning curves, explain how KNN changes with neighborhood size, and compare L1, L2, and elastic net. Focus on leakage-safe validation, feature scaling, correlated predictors, and practical model-selection trade-offs.