How L2 logistic regression splits weight between two duplicate feature columns
Role: Data Scientist
Category: Machine Learning
Difficulty: medium
Interview Round: Other
Given a standardized float64 design matrix `X` of shape `(n_samples, n_features)` whose columns `j1` and `j2` are exact duplicates, and binary labels `y` in `{0, 1}`, implement `duplicate_column_weight_split(X, y, j1, j2)`. Fit an L2 logistic regression and return `(coef_j1, coef_j2)` as two Python `float`s, which should be equal up to solver tolerance.
Requirements:
- Fit `LogisticRegression` with exactly: `penalty='l2'`, `C=1.0`, `solver='lbfgs'`, `fit_intercept=True`, `max_iter=20000`, `tol=1e-12`.
- Return `(float(model.coef_.ravel()[j1]), float(model.coef_.ravel()[j2]))`.
```hint What the loss can see
Write the logit for one sample and collect the two duplicated terms. Which combination of `w_j1` and `w_j2` does the log-loss actually depend on?
```
```hint Swap the weights
Take an optimal solution and swap the values of `w_j1` and `w_j2`. Compare the objective before and after, then think about how many minimizers a strictly convex function can have.
```
### What a Strong Answer Covers
- A fit with exactly the specified hyperparameters, with the two coefficients returned as plain floats.
- An argument for the equal split that uses both the structure of the loss and the uniqueness of the penalized minimizer.
- What happens to identifiability of the individual coefficients when the penalty is removed.
- What duplicating a column does to the effective penalty on the shared signal.
### Follow-up Questions
- Why does an unpenalized fit on duplicated columns have no unique solution?
- What would L1 do with the same duplicated columns?
- If column `j2` were exactly twice column `j1` instead of a copy, how would L2 split the weight?
Overview: Fit an L2-regularized logistic regression on a design matrix with two identical columns and report both coefficients. It tests reasoning about strict convexity, uniqueness of the penalized minimizer, identifiability without a penalty, and how L1 and L2 treat redundant features.