What are the trade-offs between solvers like lbfgs, liblinear, saga, and newton-cg when fitting logistic regression?
Role: Data Scientist
Category: Machine Learning
Difficulty: medium
Interview Round: Other
Scikit-learn's `LogisticRegression` lets you choose the optimizer through its `solver` argument. What are the trade-offs between solvers like `lbfgs`, `liblinear`, `saga`, and `newton-cg` when fitting logistic regression, and how would you pick one for a given dataset?
```hint Compare along a few axes
For each solver, ask which penalties it accepts, how its cost grows with the number of rows and features, and whether it fits a true multinomial model when there are more than two classes.
```
```hint Watch the preprocessing
Some of these optimizers are far more sensitive to feature scale than others. Think about which ones and why.
```
### What a Strong Answer Covers
- The optimization method behind each solver (quasi-Newton, truncated Newton, coordinate descent, stochastic average gradient) and what it implies for cost per iteration.
- Which penalties each solver supports, including which one handles elastic net.
- How each handles three or more classes: a multinomial model or one-vs-rest.
- How dataset size, sparsity and feature count drive the choice.
- Practical issues such as feature scaling, convergence warnings and `max_iter`.
### Follow-up Questions
- Your `lbfgs` fit raises a ConvergenceWarning. What do you check and change, in order?
- Why does `liblinear` treat the intercept differently from the other solvers, and when does that matter?
- When would you pick `sag` over `saga`, or `newton-cholesky` over `newton-cg`?
- How would you fit an L1-regularized logistic regression on data that does not fit in memory?
Overview: Compares the lbfgs, liblinear, saga and newton-cg solvers for fitting logistic regression. Tests whether you know which penalties and multiclass modes each one supports, how each scales with rows and features, and why feature scaling affects convergence.