← Pinterest Interview Insights

Pinterest·Machine Learning Engineer·Technical Phone Screen·Senior

Senior
Jun 2026

Summary

Pinterest ML Engineer technical screen, basically one big coding question the whole time. You build a Naive Bayes classifier from scratch using NumPy and then defend your design choices. Pretty focused interview, no fluff.

Questions Asked (1)

Q1

Implement a Naive Bayes classifier from scratch using NumPy. Your implementation should handle fitting class priors and per-class feature likelihoods, and predicting new samples using log-space computations for numerical stability.

Algorithms & Data StructuresTechnical Trade-offs
Author's notes

I asked upfront whether they wanted Gaussian or Multinomial and they said Gaussian, which helped a lot.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Start by clarifying the problem: assume Gaussian Naive Bayes for continuous features unless specified otherwise. Outline the mathematical formulas for priors and likelihoods, then implement a class with fit and predict methods using NumPy, ensuring log-space computations to avoid underflow. Finally, discuss trade-offs and potential improvements.

Pro tip: Mention that you use the log-sum-exp trick for predicting probabilities, and that you validate with a small dataset to ensure correctness. This shows attention to numerical stability and testing.

1. Clarify assumptions and requirements

Ask if features are continuous (Gaussian NB) or discrete (Multinomial/Bernoulli), and confirm the need for log-space computations. This ensures alignment with the interviewer's expectations.

2. Derive the math

Write down the formulas for class priors (P(y)) and conditional probabilities (P(x_i|y)) for the chosen variant. For Gaussian, include mean and variance per feature per class.

3. Implement fit method

Compute class priors and per-class feature statistics (e.g., mean, variance) using NumPy operations, ensuring vectorization for efficiency.

4. Implement predict method with log-space

For each sample, compute log-priors and log-likelihoods, sum them, and predict the class with the highest log-posterior. Use log-sum-exp for probability outputs if needed.

5. Discuss trade-offs and extensions

Talk about handling zero probabilities (Laplace smoothing), computational complexity, and how to extend to other NB variants. Mention potential pitfalls like feature independence assumption.

Key Points to Mention

  • Naive Bayes assumption: conditional independence of features given the class.
  • Gaussian Naive Bayes formulas: mean and variance per feature per class.
  • Log-space computations to prevent underflow: sum of logs instead of product of probabilities.
  • Laplace smoothing for discrete features to handle zero counts.
  • Vectorization with NumPy for efficiency: avoid loops where possible.
  • Evaluation metrics and validation: use accuracy, confusion matrix, or log-loss.

AI-generated suggestions, not part of the candidate's original notes. May be inaccurate — verify before relying on them.