Why do logistic regression fits differ between scikit-learn and statsmodels?

Quick Overview

Explain why the same logistic regression can give different coefficients in scikit-learn and statsmodels, and how to make the two fits agree. Tests knowledge of default regularization, intercept handling, solver convergence, separation, and the split between predictive and inferential tooling.

Why do logistic regression fits differ between scikit-learn and statsmodels?

Role: Data Scientist

Category: Machine Learning

Difficulty: medium

Interview Round: Other

Why can a logistic regression fit differ between `scikit-learn` and `statsmodels`, given that `scikit-learn` regularizes by default and `statsmodels` requires an explicit intercept? Explain what each library fits by default and how you would make the two agree. ```hint Write down both objectives Write the exact objective each library minimizes with its default settings, including every parameter that appears in it. ``` ```hint Check the design matrix Look at which columns each library actually puts in the model when you pass it the same feature array. ``` ### What a Strong Answer Covers - The default objective each library solves and how the penalty changes the coefficients - How each library handles the intercept, including the formula interface - The settings that make the two fits agree, and how to check that they do - Other sources of disagreement such as feature scaling, solver convergence and separation - What each library is designed to report ### Follow-up Questions - After you turn off the penalty, the coefficients still differ in the third decimal place. What would you check? - Why do regularized coefficients from scikit-learn not come with valid standard errors? - What happens in each library when the classes are perfectly separable? - How does standardizing the features change the regularized fit, and why does it leave the unregularized fit's predictions unchanged?

Overview: Explain why the same logistic regression can give different coefficients in scikit-learn and statsmodels, and how to make the two fits agree. Tests knowledge of default regularization, intercept handling, solver convergence, separation, and the split between predictive and inferential tooling.

Nov 25, 2026
mediumData ScientistOtherMachine Learning
0
0

Why can a logistic regression fit differ between scikit-learn and statsmodels, given that scikit-learn regularizes by default and statsmodels requires an explicit intercept? Explain what each library fits by default and how you would make the two agree.

What a Strong Answer Covers Guidance

  • The default objective each library solves and how the penalty changes the coefficients
  • How each library handles the intercept, including the formula interface
  • The settings that make the two fits agree, and how to check that they do
  • Other sources of disagreement such as feature scaling, solver convergence and separation
  • What each library is designed to report

Follow-up Questions Guidance

  • After you turn off the penalty, the coefficients still differ in the third decimal place. What would you check?
  • Why do regularized coefficients from scikit-learn not come with valid standard errors?
  • What happens in each library when the classes are perfectly separable?
  • How does standardizing the features change the regularized fit, and why does it leave the unregularized fit's predictions unchanged?