← Google Interview Insights

Google·Data Scientist·Technical Phone Screen·Senior

Senior
Jul 2026

Summary

Google data scientist interview that went deep on imbalanced classification, specifically a multi-part question covering metric selection, threshold analysis in Python, AUPRC computation, and cost-sensitive threshold picking. The whole thing felt like one long problem that kept branching.

Questions Asked (4)

Q1

You have a dataset with true labels and predicted probabilities, and the positive class is only about 5% of the data. Which evaluation metrics would you prioritize and why? What are the pitfalls of using accuracy or ROC-AUC in this kind of heavy class imbalance?

Product Analytics & MetricsTechnical Trade-offs
Author's notes

This part I actually felt okay about.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Start by acknowledging the severe class imbalance and its impact on evaluation. Then, discuss why accuracy and ROC-AUC can be misleading, and recommend metrics like precision-recall AUC, F1-score, and recall at a fixed precision, tailored to the business objective. Finally, emphasize the importance of aligning metric choice with the specific costs of false positives and false negatives.

Pro tip: Always tie the metric choice back to the business problem: for example, in fraud detection, you might prioritize recall at a high precision to minimize false alarms while catching most fraud. Mention that PR-AUC is more informative than ROC-AUC when the positive class is rare.

1. Acknowledge the imbalance

State that with only 5% positives, the dataset is heavily imbalanced, and standard metrics like accuracy can be misleading.

2. Explain pitfalls of accuracy and ROC-AUC

Accuracy is misleading because a model predicting all negatives achieves 95% accuracy. ROC-AUC can be overly optimistic because it considers both classes equally and the false positive rate can be low even with many false positives when negatives dominate.

3. Recommend appropriate metrics

Suggest precision-recall AUC (PR-AUC), F1-score, and recall at a fixed precision (or precision at a fixed recall) as better alternatives. Also consider cost-sensitive metrics if costs are known.

4. Align with business objective

Discuss how the choice depends on the relative costs of false positives and false negatives. For example, in medical diagnosis, high recall might be prioritized, while in spam detection, high precision might be more important.

5. Consider additional techniques

Mention that resampling, class weights, or threshold tuning can help, but the evaluation should still use the recommended metrics.

Key Points to Mention

  • Accuracy paradox: high accuracy can be achieved by predicting the majority class.
  • ROC-AUC may not reflect performance on the minority class because it incorporates true negatives.
  • Precision-recall AUC focuses on the minority class and is more informative for imbalanced data.
  • F1-score balances precision and recall, useful when both are important.
  • Recall at a fixed precision (or precision at a fixed recall) aligns with business constraints.
  • Cost-sensitive evaluation: incorporate the actual costs of false positives and false negatives.

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

Q2

Write a Python function that takes the actual labels and predicted probabilities and returns thresholds, precision, recall, and F1 across all unique predicted probability values. Handle ties in scores, empty denominators, and enforce monotonic precision if needed.

Algorithms & Data StructuresTechnical Trade-offs
Author's notes

This is where I slowed down.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Start by clarifying the function signature and expected output format, then outline a vectorized approach using NumPy to compute precision, recall, and F1 for each unique threshold. Emphasize handling ties by grouping equal scores, avoiding division by zero, and enforcing monotonic precision via cumulative maximum.

Pro tip: Mention that you would sort scores descending and use cumulative sums to compute metrics efficiently in O(n log n), and that you would test edge cases like all predictions positive or negative. Also, note that enforcing monotonic precision is a common post-processing step to ensure a valid precision-recall curve.

1. Clarify requirements and edge cases

Confirm the input format (actual labels as binary array, predicted probabilities as float array) and output (arrays of thresholds, precision, recall, F1). Discuss handling of ties, empty denominators, and monotonic precision.

2. Sort and group by unique scores

Sort the predicted probabilities in descending order along with the true labels. Identify unique score values to use as thresholds, ensuring ties are handled by grouping equal scores together.

3. Compute cumulative TP, FP, FN

Iterate through the sorted scores, accumulating true positives (TP), false positives (FP), and false negatives (FN) at each unique threshold. Use vectorized operations for efficiency.

4. Calculate precision, recall, F1 with safeguards

Compute precision = TP / (TP + FP), recall = TP / (TP + FN), and F1 = 2 * precision * recall / (precision + recall). Handle zero denominators by setting the metric to 0 (or 1 for recall when no positives? Actually, standard: if denominator is 0, set metric to 0).

5. Enforce monotonic precision and return results

Apply a cumulative maximum to precision to ensure it is non-increasing as threshold decreases (or non-decreasing as threshold increases). Return the arrays of thresholds, precision, recall, and F1.

Key Points to Mention

  • Use of NumPy for vectorized operations to achieve O(n log n) time complexity.
  • Handling ties by grouping equal predicted probabilities to avoid duplicate thresholds.
  • Edge cases: no positive predictions (precision undefined), no actual positives (recall undefined), and empty input.
  • Monotonic precision enforcement via cumulative maximum to produce a valid precision-recall curve.
  • Trade-offs between threshold granularity and computational efficiency.
  • Potential need to return thresholds in a specific order (e.g., descending) for plotting.

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

Q3

How would you compute AUPRC efficiently, and what effect does score calibration have on the PR curve?

Product Analytics & MetricsTechnical Trade-offs
Author's notes

Efficient AUPRC is just the trapezoidal rule or the step-function interpolation after sorting by threshold, nothing exotic.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Start by explaining the efficient computation of AUPRC using sorting and cumulative sums, emphasizing O(n log n) complexity. Then discuss how score calibration affects the PR curve, noting that while ranking metrics like AUPRC are invariant to monotonic transformations, calibration impacts the curve's shape and interpretability, especially when scores are used as probabilities.

Pro tip: Mention that in practice, AUPRC is often computed using the trapezoidal rule on the precision-recall curve, but be aware that this can be biased; the step-wise interpolation is more accurate. Also, highlight that calibration is crucial when the PR curve is used to set thresholds for business decisions.

1. Define AUPRC and its importance

Briefly define AUPRC as the area under the precision-recall curve, which is particularly useful for imbalanced datasets. Explain why it's preferred over ROC AUC in such cases.

2. Efficient computation algorithm

Describe sorting predictions in descending order, then computing cumulative true positives and false positives to derive precision and recall at each threshold. Use numerical integration (e.g., trapezoidal rule) to compute the area.

3. Complexity and optimizations

State that the algorithm runs in O(n log n) due to sorting, and mention potential optimizations like using approximate methods for large datasets or parallelization.

4. Effect of score calibration

Explain that calibration transforms scores to probabilities, which can change the PR curve's shape but not the ranking (thus AUPRC remains the same if the transformation is monotonic). However, calibration affects the interpretability of precision and recall at specific thresholds.

5. Practical implications

Discuss how calibration impacts decision-making, such as threshold selection, and note that well-calibrated scores make the PR curve more reliable for estimating true performance.

Key Points to Mention

  • AUPRC is invariant to monotonic transformations of scores, so calibration does not change the AUPRC value if the ranking is preserved.
  • Calibration affects the PR curve's shape and the precision/recall values at given thresholds, which matters for operational decisions.
  • Efficient computation uses sorting and cumulative sums, with O(n log n) time complexity.
  • For imbalanced data, AUPRC is more informative than ROC AUC.
  • The trapezoidal rule for AUC can be biased; step-wise interpolation or average precision is often preferred.
  • Calibration methods include Platt scaling, isotonic regression, and histogram binning.

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

Q4

How would you choose an operating threshold given that false positives and false negatives have different costs, and there are volume constraints on how many positives you can act on?

Product Analytics & MetricsA/B Testing & Experimentation
Author's notes

Felt like the most practical part of the whole question.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Frame the problem as a constrained optimization: define a cost function that weights false positives and false negatives by their business costs, then find the threshold that minimizes total cost subject to the volume constraint. Walk through how you would estimate costs, incorporate the constraint, and validate the chosen threshold with a holdout set or simulation.

Pro tip: Mention that the optimal threshold is not just about costs—it's also about capacity and fairness; sometimes you need to prioritize within the positive set (e.g., by expected value) rather than just cut off by score. Also, always sanity-check with a small-scale live experiment before full deployment.

1. Define the cost matrix

Quantify the business cost of a false positive (e.g., wasted resource, user annoyance) and a false negative (e.g., missed fraud, lost revenue). Express both in a common unit, such as dollars.

2. Model the volume constraint

Determine the maximum number of positives you can act on per unit time (e.g., daily review capacity). This imposes a hard limit on the number of predicted positives.

3. Optimize threshold under constraint

Using a validation set, compute the expected total cost for each threshold. Find the threshold that minimizes cost while ensuring the predicted positive volume does not exceed the constraint. If the unconstrained optimum violates the constraint, choose the threshold at the constraint boundary.

4. Validate and iterate

Evaluate the chosen threshold on a holdout set or via simulation. Monitor performance in a live A/B test, and be prepared to adjust as costs or volumes change.

Key Points to Mention

  • Cost-sensitive learning: weighting errors by their costs rather than treating them equally.
  • Precision-recall trade-off and how it shifts with threshold.
  • Volume constraint as a business capacity limit, not just a statistical one.
  • Using a validation set to estimate costs and volumes at different thresholds.
  • The importance of aligning with stakeholders to quantify costs and constraints.
  • Monitoring and re-evaluating the threshold as business conditions change.

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