LinkedIn·Machine Learning Engineer·Technical Phone Screen
- Given a JSON object where each key is a class label mapping to a list of samples, implement a stratified sampling function that either samples uniformly within each class or draws N total samples with proportional class representation. The solution must be seeded for reproducibility and handle edge cases like empty classes, oversized sample requests, and single-class inputs.
- Why is stratified sampling preferable to flat uniform sampling for imbalanced datasets, and what bias does flat sampling introduce?
“This took longer than I expected to get right.”