Return positive-class probabilities from a scikit-learn logistic regression
Role: Data Scientist
Category: Machine Learning
Difficulty: easy
Interview Round: Other
Implement `positive_class_proba(X_train, y_train, X_test)`. It fits a binary scikit-learn `LogisticRegression` on the training data and returns $P(y=1)$ for each row of `X_test`, which is column 1 of `predict_proba(X_test)` (the columns follow `model.classes_`).
Requirements:
- Pin the hyperparameters: `penalty='l2'`, `C=1.0`, `solver='lbfgs'`, `max_iter=1000`, `tol=1e-6`, `fit_intercept=True`.
- Return a 1-D `np.ndarray` of shape `(n_test,)` with dtype `float64`.
- Each value lies strictly in (0, 1).
```hint Column order
Check which attribute of the fitted model decides the order of the `predict_proba` columns, and where label 1 lands in it.
```
### Constraints & Assumptions
- `X_train` has shape `(n_train, n_features)` and `X_test` has shape `(n_test, n_features)`, with the same features in the same order.
- `y_train` has shape `(n_train,)` and holds the labels 0 and 1, both present.
- NumPy and scikit-learn are available.
### What a Strong Answer Covers
- Building the estimator with exactly the pinned hyperparameters, so the fit is reproducible.
- Why the positive-class probability sits in column 1, tied to how scikit-learn orders `classes_`.
- Returning a 1-D `float64` array of length `n_test` instead of the full two-column matrix.
- Why the values fall strictly between 0 and 1, and whether floating point can break that.
### Follow-up Questions
- Why look up the column through `model.classes_` instead of hardcoding column 1?
- What changes if the labels are strings such as `"fraud"` and `"legit"`, or -1 and 1?
- How would you compute the same probabilities from `decision_function` alone?
- Are these probabilities calibrated, and how would you check?
Overview: Fit a binary scikit-learn logistic regression with pinned hyperparameters and return the probability of the positive class for every test row. It tests how predict_proba orders its columns through classes_, the expected output shape and dtype, and why sigmoid outputs stay between 0 and 1.