Reconfigure a scikit-learn Pipeline's logistic regression with set_params
Role: Data Scientist
Category: Machine Learning
Difficulty: easy
Interview Round: Other
Implement `def reconfigure_pipeline(X_train, y_train, X_test) -> tuple[np.ndarray, str]`. Build a scaler plus logistic regression `Pipeline`, reconfigure the classifier through the pipeline using `<step>__<param>` syntax, fit it, and return the test predictions plus the solver name read back from the pipeline's params.
Requirements:
- Build `Pipeline([('scaler', StandardScaler()), ('clf', LogisticRegression(penalty='l2', C=1.0, solver='lbfgs', max_iter=1000, tol=1e-6))])`.
- Call `pipe.set_params(clf__solver='liblinear', clf__max_iter=2000, clf__dual=False, clf__random_state=0)`. Do not rebuild the estimator or the pipeline.
- Fit on `(X_train, y_train)` and return `(predictions, solver_name)`.
- `predictions` is a 1-D integer array of shape `(n_test,)` from `pipe.predict(X_test)`.
- `solver_name` is a plain `str` read from `pipe.get_params()['clf__solver']` (it must be `'liblinear'`), not hardcoded.
```hint Parameter names
A pipeline's parameter names join the step name and the estimator's own parameter name. Printing pipe.get_params().keys() shows the exact spelling.
```
### Constraints & Assumptions
- `numpy` and `scikit-learn` are available.
- Inputs are valid, dense arrays.
### What a Strong Answer Covers
- Building the pipeline with the exact step names and initial classifier settings
- Changing the existing classifier through `set_params` with `clf__` keys, without constructing a new estimator
- Fitting the whole pipeline so the scaler learns from the training data only, then predicting on the test set
- Reading the solver back from `get_params()` as a plain `str` and returning the right types and shapes
### Follow-up Questions
- How does `set_params` resolve a key like `clf__solver`?
- Why prefer `set_params` over rebuilding the pipeline?
- How would you swap out or disable the scaler step without rebuilding the pipeline?
Overview: Build a scikit-learn Pipeline with StandardScaler and LogisticRegression, then change the classifier's solver and settings through set_params using step__param keys before fitting. It tests nested parameter addressing, in-place reconfiguration and reading values back with get_params.