PracHub
QuestionsPremiumCoachesLearningGuidesInterview Prep
|Home/Coding & Algorithms/Microsoft

Compute and plot a precision–recall curve

Last updated: Mar 29, 2026

Quick Overview

This implementation-level question evaluates understanding of precision–recall curve computation and related binary classification metrics, including threshold sweeping, ranking by predicted score, handling ties, and edge cases such as no predicted positives or datasets with zero positives; Category/Domain: Coding & Algorithms, Data Science (Position: Data Scientist). It is commonly asked because it verifies practical ability to build evaluation pipelines and reason about classifier performance under class imbalance and scoring ties, and to extend results to aggregate measures like Average Precision / PR-AUC.

  • easy
  • Microsoft
  • Coding & Algorithms
  • Data Scientist

Compute and plot a precision–recall curve

Company: Microsoft

Role: Data Scientist

Category: Coding & Algorithms

Difficulty: easy

Interview Round: Technical Screen

You are given model outputs for a binary classifier: - `y_true`: an array of 0/1 ground-truth labels of length `n`. - `y_score`: an array of predicted scores/probabilities in `[0, 1]` of length `n`. Write code (language of your choice) to generate the **precision–recall (PR) curve**. Requirements: 1. Sort examples by `y_score` descending and sweep a threshold from high to low. 2. At each unique threshold (or each rank), compute: - `precision = TP / (TP + FP)` - `recall = TP / (TP + FN)` 3. Return arrays of `(recall_points, precision_points)` suitable for plotting. 4. Handle edge cases: - no predicted positives (define precision as 1 or 0—state your convention), - ties in scores, - datasets with zero positives. Optional follow-up: compute **Average Precision (AP)** / PR-AUC from the curve.

Quick Answer: This implementation-level question evaluates understanding of precision–recall curve computation and related binary classification metrics, including threshold sweeping, ranking by predicted score, handling ties, and edge cases such as no predicted positives or datasets with zero positives; Category/Domain: Coding & Algorithms, Data Science (Position: Data Scientist). It is commonly asked because it verifies practical ability to build evaluation pipelines and reason about classifier performance under class imbalance and scoring ties, and to extend results to aggregate measures like Average Precision / PR-AUC.

Related Interview Questions

  • Return Top K Open Businesses - Microsoft (hard)
  • Implement Memory Allocation and In-Memory Records - Microsoft (medium)
  • Implement K-Means and Detect Divisible Subarrays - Microsoft (medium)
  • Sort Three Categories In Place - Microsoft (medium)
  • Retain Top K Elements - Microsoft (medium)
Microsoft logo
Microsoft
Nov 24, 2025, 12:00 AM
Data Scientist
Technical Screen
Coding & Algorithms
1
0

You are given model outputs for a binary classifier:

  • y_true : an array of 0/1 ground-truth labels of length n .
  • y_score : an array of predicted scores/probabilities in [0, 1] of length n .

Write code (language of your choice) to generate the precision–recall (PR) curve.

Requirements:

  1. Sort examples by y_score descending and sweep a threshold from high to low.
  2. At each unique threshold (or each rank), compute:
    • precision = TP / (TP + FP)
    • recall = TP / (TP + FN)
  3. Return arrays of (recall_points, precision_points) suitable for plotting.
  4. Handle edge cases:
    • no predicted positives (define precision as 1 or 0—state your convention),
    • ties in scores,
    • datasets with zero positives.

Optional follow-up: compute Average Precision (AP) / PR-AUC from the curve.

Submit Your Answer

Sign in to leave a comment

Loading comments...

Browse More Questions

More Coding & Algorithms•More Microsoft•More Data Scientist•Microsoft Data Scientist•Microsoft Coding & Algorithms•Data Scientist Coding & Algorithms
PracHub

Master your tech interviews with 8,500+ real questions from top companies.

Product

  • Questions
  • Learning Tracks
  • Interview Guides
  • Resources
  • Premium
  • For Universities
  • Student Access

Browse

  • By Company
  • By Role
  • By Category
  • Topic Hubs
  • SQL Questions
  • Compare Platforms
  • Discord Community

Support

  • support@prachub.com
  • (916) 541-4762

Legal

  • Privacy Policy
  • Terms of Service
  • About Us

© 2026 PracHub. All rights reserved.