How to get the coefficients from an MLE logit regression?
Asked Answered
S

2

8

I have a statsmodels.discrete.discrete_model.BinaryResultsWrapper that was the output of running statsmodels.api.Logit(...).fit(). I can call the .summary() method which prints a table of results with the coefficients embedded in text, but what I really need is to store those coefficients into a variable for later use. How can I do this? The documentation is not really clear on how to do this very basic operation (probably the most basic thing anyone would want to do with the results, besides print them)

When I try the fittedvalues() method, which looked like it would return the coefficients, I just get the error:

'Series' object is not callable

Subserve answered 25/4, 2015 at 18:19 Comment(0)
S
7

Since the documentation is poor, I found the solution through random experimentation.

The correct syntax is:

Logit(...).fit().params.values
Subserve answered 25/4, 2015 at 18:32 Comment(4)
statsmodels.sourceforge.net/stable/generated/… It's a bit messy, but the documentation for the Results has the list of attributes.Fidellas
What confused me was that 'params' was listed as a 'Parameter' and not an 'Attribute' as is standard notation for Class documentation. A parameter is typically an argument or input to a class constructor or method, not an attribute to be invoked with dot notation.Subserve
Yes, I didn't see this before, something is messed up with sphinx documentation creation. Things like this should be reported on the statsmodels issue tracker so it gets fixed.Fidellas
Eight years later, this was not fixed.Somnifacient
I
0

First get data from model summary as a simple table (list of lists). Then convert it to a pandas dataframe. In this way you do not have to refit the model:

import pandas as pd
pd.DataFrame(model.summary().tables[1].data)
Incisive answered 18/1 at 13:23 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.