Calculate residual deviance from scikit-learn logistic regression model

2024/9/20 13:37:45

Is there any way to calculate residual deviance of a scikit-learn logistic regression model? This is a standard output from R model summaries, but I couldn't find it any of sklearn's documentation.

Answer
  1. As suggested by @russell-richie, it should be model.predict_proba
  2. Don't forget the argument normalize=False in function metrics.log_loss() to return the sum of the per-sample losses.

So to complete @ingo's answer, to obtain the model deviance with sklearn.linear_model.LogisticRegression, you can compute:

def deviance(X, y, model):return 2*metrics.log_loss(y, model.predict_proba(X), normalize=False)
https://en.xdnf.cn/q/72167.html

Related Q&A

Use Python to create 2D coordinate

I am truly a novice in Python. Now, I am doing a project which involves creating a list of 2D coordinates. The coordinates should be uniformly placed, using a square grid (10*10), like(0,0)(0,1)(0,2)(0…

How to pass Unicode title to matplotlib?

Cant get the titles right in matplotlib: technologien in C gives: technologien in CPossible solutions already tried:utechnologien in C doesnt work neither does: # -*- coding: utf-8 -*- at the beginnin…

Cythonize but not compile .pyx files using setup.py

I have a Cython project containing several .pyx files. To distribute my project I would like to provide my generated .c files as recommended in the Cython documentation, to minimize problems with diffe…

How to clear matplotlib labels in legend?

Is there a way to clear matplotlib labels inside a graphs legend? This post explains how to remove the legend itself, but the labels themselves still remain, and appear again if you plot a new figure.…

Threading and Signals problem in PyQt

Im having some problems with communicating between Threads in PyQt. Im using signals to communicate between two threads, a Sender and a Listener. The sender sends messages, which are expected to be rec…

stopping a python thread using __del__

I have a threaded program in Python that works fine except that __del__ does not get called once the thread is running:class tt(threading.Thread):def __init__(self):threading.Thread.__init__(self)self.…

Python-docx: Is it possible to add a new run to paragraph in a specific place (not at the end)

I want to set a style to a corrected word in MS Word text. Since its not possible to change text style inside a run, I want to insert a new run with new style into the existing paragraph...for p in doc…

Chained QSortFilterProxyModels

Lets say I have a list variable datalist storing 10,000 string entities. The QTableView needs to display only some of these entities. Thats is why QTableView was assigned QSortFilterProxyModel that doe…

Python subprocess.popen() without waiting

Im using Python 3.4.2 on Windows. In script1.py Im doing this:myProc = subprocess.Popen([sys.executable, "script2.py", "argument"]) myProc.communicate()it works and call script2.py …

Python27.dll File Missing - Exception

I have downloaded my code from bit-bucket which was made by my group member. It contain all the frameworks and python script folder. But when I run this code on my system it generates the following err…