The score() function computes D^2, the percentage of deviance explained, but I'd like to get the log-likelihood to calculate BIC. What's the formula to go from deviance to log-likelihood?

Score function reference:


  • 1
    $\begingroup$ There is no method to get the devaince. Sklearn focuses more on prediction that inferential stats so it lacks a lot of the functionality you would find in say R's glm. Have you looked at statsmodels? $\endgroup$ Nov 10, 2020 at 23:43
  • $\begingroup$ @DemetriPananos The link OP offered pretty much contradicts what you said $\endgroup$
    – Firebug
    Nov 11, 2020 at 0:28
  • $\begingroup$ @DemetriPananos Statsmodels is awesome, and one of their devs hangs on this Stack (I think he has email alerts for the statsmodels tag, but whatever). I remember trying to do inference on a multinomial logistic regression in Python and having a difficult time pulling out the deviance until I started using Statsmodels instead of SKLearn. It might be possible in SKL, but SM made it way easier. $\endgroup$
    – Dave
    Nov 11, 2020 at 0:36
  • $\begingroup$ @Firebug Oh, that is a new development. Hadn't caught up with that update. $\endgroup$ Nov 11, 2020 at 3:43
  • $\begingroup$ @Dave yes, I know one of the devs hangs out here. I think I've angered them once before. $\endgroup$ Nov 11, 2020 at 3:43

1 Answer 1


If you have deviance, refer to this answer, which I'll quote below:

$$\begin{matrix} \text{Null Deviance} \quad \quad \text{ } \text{ } & & \text{ } D_{TOT} = 2(\hat{\ell}_{S} - \hat{\ell}_0), \\[6pt] \text{Explained Deviance} & & D_{REG} = 2(\hat{\ell}_{p} - \hat{\ell}_0), \\[6pt] \text{Residual Deviance}^\dagger \text{ } & & \text{ } D_{RES} = 2(\hat{\ell}_{S} - \hat{\ell}_{p}). \\[6pt] \end{matrix}$$ In these expressions the value $\hat{\ell}_S$ is the maximised log-likelihood under a saturated model (one parameter per data point), $\hat{\ell}_0$ is the maximised log-likelihood under a null model (intercept only), and $\hat{\ell}_{p}$ is the maximised log-likelihood under the model (intercept term and $p$ coefficients).

So, starting from Explained Deviance, $D_{REG}$:

$$D_{REG} = 2(\hat{\ell}_{p} - \hat{\ell}_0)$$



You'll have to estimate $\hat{\ell}_0$ if you want to compute the exact value. If you simply want to compare models, then that term is constant among them, and can be safely ignored.

Ben (https://stats.stackexchange.com/users/173082/ben), Is R-squared truly an invalid metric for non-linear models?, URL (version: 2018-07-31): https://stats.stackexchange.com/q/359997


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.