Compute ROC AUC from logistic regression probabilities without thresholding
Role: Data Scientist
Category: Machine Learning
Difficulty: easy
Interview Round: Other
Implement `auc_from_probabilities(y_true, y_proba)`. `y_true` is a 1-D int ndarray of 0/1 labels and `y_proba` is the 1-D float ndarray `predict_proba(X)[:, 1]`, both shape `(n,)`. Return the ROC AUC as a Python `float`.
- Pass the continuous `y_proba` straight into `sklearn.metrics.roc_auc_score(y_true, y_proba)`.
- Do not threshold: no `(y_proba >= 0.5).astype(int)` or `predict`-style labels.
For example, with this 12-element input the function returns 0.8888..., while thresholding first would wrongly return 0.75:
```python
y_true = np.array([0, 0, 1, 0, 0, 1, 0, 1, 0, 1, 1, 1])
y_proba = np.array([0.10, 0.20, 0.35, 0.30, 0.40, 0.58,
0.55, 0.70, 0.60, 0.80, 0.90, 0.95])
auc_from_probabilities(y_true, y_proba) # -> 0.8888888...
```
```hint What AUC looks at
AUC depends only on how the scores order the positives relative to the negatives. Think about what a 0.5 threshold does to that ordering.
```
### Constraints & Assumptions
- Both classes appear in `y_true`.
- The result is graded with `assert_allclose(rtol=1e-9)`.
### What a Strong Answer Covers
- Passing the positive-class probability column straight to `roc_auc_score` and returning a plain Python float.
- What ROC AUC measures, stated in terms of pairs of one positive and one negative example.
- What thresholding does to the scores and why the AUC changes as a result.
- The input mistakes that silently give a wrong number, and the case where AUC is undefined.
### Follow-up Questions
- Why does passing thresholded labels give a different AUC instead of an error?
- Would the AUC change if you passed `decision_function(X)` instead of the probabilities?
- How would you extend this to multiclass?
Overview: Compute ROC AUC for a logistic regression from its predicted positive-class probabilities with scikit-learn. It tests what AUC measures as a ranking metric, what a 0.5 threshold does to the score, and the input mistakes that quietly return a wrong number.