AI Notes
Complete ML interview prep. Algorithms, optimization. Interview 2024.
Introduction
Machine learning interviews evaluate your ability to reason about algorithms, design systems, and make engineering tradeoffs. Interviewers look for structured thinking, mathematical intuition, and practical experience. This guide covers the most common questions organized by topic, with detailed answers that demonstrate the depth of understanding expected at top tech companies.
Supervised Learning Questions
Q1: Explain the bias-variance tradeoff with a concrete example.
| Prediction | price = $200K + $50 × bedrooms |
| Reality | Prices depend on location, size, condition, market, etc. |
| Error | Consistently underpredicts mansions, overpredicts shacks |
| Training error | High | Test error: High |
| On new data | Wild predictions between training points |
| Training error | ~0 | Test error: Very high |
| Training error | Moderate | Test error: Moderate |
Q2: When would you use Random Forest vs Gradient Boosting?
Random Forest
- Trains trees independently (parallelizable)
- Less prone to overfitting (bagging reduces variance)
- Less hyperparameter tuning needed
- Better when: Limited tuning time, noisy data, need robust baseline
Gradient Boosting (XGBoost/LightGBM)
- Trains trees sequentially (each corrects previous errors)
- Can overfit if not regularized (reduce bias)
- Typically higher accuracy with proper tuning
- Better when: You can invest time in tuning, structured/tabular data
Key difference
RF: Many deep trees averaged → reduce VARIANCE
GB: Many shallow trees summed → reduce BIAS
Q3: How do you handle class imbalance?
| Scenario | Fraud detection (0.1% positive, 99.9% negative) |
| - Oversampling minority class (SMOTE | synthesize new minority samples) |
| - Combination | SMOTE + undersampling majority |
| - Class weights | Give minority class higher loss weight |
| - Threshold adjustment | Instead of 0.5, use lower threshold for positive |
| - USE | Precision-Recall curve, F1, AUC-ROC |
Q4: Explain cross-validation and when stratified K-fold matters.
K-Fold Cross-Validation
1. Split data into K equal folds (typically K=5 or 10)
2. For each fold i:
- Train on all folds except i
- Evaluate on fold i
3. Average performance across all K evaluations
Fold 1: [Test] [Train] [Train] [Train] [Train]
Fold 2: [Train] [Test] [Train] [Train] [Train]
Fold 3: [Train] [Train] [Test] [Train] [Train]
Fold 4: [Train] [Train] [Train] [Test] [Train]
Fold 5: [Train] [Train] [Train] [Train] [Test]
Stratified K-Fold
Maintains class distribution in each fold
Critical when: Classes are imbalanced
Without stratification: Some folds might have 0 minority samples!
Deep Learning Questions
Q5: What happens if learning rate is too high or too low?
| Symptom: Loss | NaN or spikes repeatedly |
| Symptom | Loss barely changes over many epochs |
| - LR range test | Increase LR exponentially, plot loss vs LR |
| - Typical ranges | 1e-4 to 1e-2 for Adam, 1e-2 to 0.1 for SGD |
Q6: Explain attention mechanism in transformers.
| Core idea | Let each token "look at" all other tokens to gather context |
| Input | "The cat sat on the mat" |
| Query (what am I looking for?) | derived from "sat" embedding |
| Key (what do I contain?) | derived from each token's embedding |
| Value (what information do I provide?) | derived from each token |
| Attention scores | Q_sat · K_the, Q_sat · K_cat, Q_sat · K_sat, ... |
| After softmax | [0.05, 0.35, 0.10, 0.15, 0.05, 0.30] |
| Output | Weighted sum of Values using these attention weights |
| Result | "sat" representation enriched with info about WHO sat WHERE |
System Design Questions
Q7: Design a content recommendation system for a news app.
| - Users | 10M daily active |
| - Content | 10K new articles/day |
| - Latency | <100ms per request |
| - Optimize | Click-through rate + reading time |
| - Collaborative filtering | users like you read X |
| - Content-based | similar to articles you've read |
| - Trending | popular in your region/interests |
| Ranking (score 1000 | select top 20): |
| - Features | user history, article embeddings, freshness, |
| - Model | Deep neural network predicting P(click) and P(read) |
| - Diversity | Don't show all articles from same topic |
| - Freshness | Boost recently published content |
| - Quality | Penalize clickbait (low read-time/click ratio) |
Practical Coding Questions
Summary
Machine learning interviews test breadth (knowing many algorithms), depth (understanding mathematical foundations), and practical wisdom (knowing which approach to use when). Structure your answers clearly: state the concept, give the formula or algorithm, provide intuition for why it works, discuss tradeoffs, and give a practical example. The best candidates demonstrate they can reason through novel problems using fundamental principles, not just recall memorized definitions.
Exam Focus
Revise definitions, diagrams, examples, and short-answer points for ML Interview Questions.
Interview Use
Prepare one clear explanation, one practical example, and one common mistake for this Artificial Intelligence topic.
Search Terms
artificial-intelligence, artificial intelligence, artificial, intelligence, interview, preparation, machine, learning
Related Artificial Intelligence Topics