cas5nq
cas5nq

Reputation: 413

How to get the coefficients from an MLE logit regression?

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

Upvotes: 8

Views: 8998

Answers (2)

Andrew_Stark
Andrew_Stark

Reputation: 1

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)

Upvotes: 0

cas5nq
cas5nq

Reputation: 413

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

The correct syntax is:

Logit(...).fit().params.values

Upvotes: 7

Related Questions