Return the full, unpruned ROC curve for a logistic model's predicted probabilities

Quick Overview

Implement a function that returns every point of a logistic model's ROC curve with scikit-learn's roc_curve, keeping all intermediate thresholds. It tests how ROC points map to distinct probability thresholds, why the first threshold is infinite, and what the default point pruning removes.

Return the full, unpruned ROC curve for a logistic model's predicted probabilities

Role: Data Scientist

Category: Machine Learning

Difficulty: easy

Interview Round: Other

Implement `roc_points(y_true, y_proba)` that returns the full ROC curve of a logistic model's predicted probabilities as a tuple `(fpr, tpr, thresholds)`, each a 1-D float `np.ndarray`. Compute it with `sklearn.metrics.roc_curve(y_true, y_proba, drop_intermediate=False)`. Requirements: - Pass `drop_intermediate=False` (the default `True` drops collinear points) and return the tuple unchanged, with no post-processing or trimming. - For n distinct probabilities each array has length n + 1, because of the prepended point at `(fpr=0, tpr=0)`. The grader's 12-element input yields 13 points; the default setting would give 8. - `fpr` and `tpr` are non-decreasing, and `thresholds` is strictly decreasing. - `thresholds[0]` is `np.inf` (scikit-learn 1.3 and later) and is not a usable cutoff. - The result is graded with `assert_allclose` (`equal_nan=False`; a leading `inf` matches `inf`). ```hint Count the points Each distinct probability is one place where the curve can move. Work out which of those points the default setting removes, and what the one extra point at the start stands for. ``` ### Constraints & Assumptions - `y_true` and `y_proba` are 1-D arrays of the same length. - `y_true` holds binary labels in {0, 1}. - `y_proba` holds the model's predicted probability of the positive class, with values in [0, 1]. - scikit-learn is version 1.3 or later, so the leading threshold is `np.inf`. ### What a Strong Answer Covers - Calls `roc_curve` with `drop_intermediate=False` and returns the three arrays without slicing, sorting or rounding them. - Explains why the full curve has n + 1 points for n distinct probabilities and what the leading `np.inf` threshold means. - Explains which points the default `drop_intermediate=True` removes and why the curve's shape and AUC stay the same. - Describes how tied probabilities change the number of points. - States the order of each returned array: non-decreasing rates and strictly decreasing thresholds. ### Follow-up Questions - Why does `drop_intermediate=True` exist if it changes the output length? - How would you pick a single operating threshold from these arrays? - What does `roc_curve` return when `y_true` contains only one class? - How would you compute the same three arrays without scikit-learn?

Overview: Implement a function that returns every point of a logistic model's ROC curve with scikit-learn's roc_curve, keeping all intermediate thresholds. It tests how ROC points map to distinct probability thresholds, why the first threshold is infinite, and what the default point pruning removes.

General logo
General
Nov 24, 2026
easyData ScientistOtherMachine Learning
0
0

Implement roc_points(y_true, y_proba) that returns the full ROC curve of a logistic model's predicted probabilities as a tuple (fpr, tpr, thresholds), each a 1-D float np.ndarray. Compute it with sklearn.metrics.roc_curve(y_true, y_proba, drop_intermediate=False).

Requirements:

  • Pass drop_intermediate=False (the default True drops collinear points) and return the tuple unchanged, with no post-processing or trimming.
  • For n distinct probabilities each array has length n + 1, because of the prepended point at (fpr=0, tpr=0) . The grader's 12-element input yields 13 points; the default setting would give 8.
  • fpr and tpr are non-decreasing, and thresholds is strictly decreasing.
  • thresholds[0] is np.inf (scikit-learn 1.3 and later) and is not a usable cutoff.
  • The result is graded with assert_allclose ( equal_nan=False ; a leading inf matches inf ).

Constraints & Assumptions

  • y_true and y_proba are 1-D arrays of the same length.
  • y_true holds binary labels in {0, 1}.
  • y_proba holds the model's predicted probability of the positive class, with values in [0, 1].
  • scikit-learn is version 1.3 or later, so the leading threshold is np.inf .

What a Strong Answer Covers Guidance

  • Calls roc_curve with drop_intermediate=False and returns the three arrays without slicing, sorting or rounding them.
  • Explains why the full curve has n + 1 points for n distinct probabilities and what the leading np.inf threshold means.
  • Explains which points the default drop_intermediate=True removes and why the curve's shape and AUC stay the same.
  • Describes how tied probabilities change the number of points.
  • States the order of each returned array: non-decreasing rates and strictly decreasing thresholds.

Follow-up Questions Guidance

  • Why does drop_intermediate=True exist if it changes the output length?
  • How would you pick a single operating threshold from these arrays?
  • What does roc_curve return when y_true contains only one class?
  • How would you compute the same three arrays without scikit-learn?