Python 2.7 - statsmodels - formatting and writing summary output

后端 未结 5 1718
独厮守ぢ
独厮守ぢ 2021-02-05 20:55

I\'m doing logistic regression using pandas 0.11.0(data handling) and statsmodels 0.4.3 to do the actual regression, on Mac OSX Lion.

I\'m goin

5条回答
  •  野趣味
    野趣味 (楼主)
    2021-02-05 21:52

    I found this formulation to be a little more straightforward. You can add/subtract columns by following the syntax from the examples (pvals,coeff,conf_lower,conf_higher).

    import pandas as pd     #This can be left out if already present...
    
    def results_summary_to_dataframe(results):
        '''This takes the result of an statsmodel results table and transforms it into a dataframe'''
        pvals = results.pvalues
        coeff = results.params
        conf_lower = results.conf_int()[0]
        conf_higher = results.conf_int()[1]
    
        results_df = pd.DataFrame({"pvals":pvals,
                                   "coeff":coeff,
                                   "conf_lower":conf_lower,
                                   "conf_higher":conf_higher
                                    })
    
        #Reordering...
        results_df = results_df[["coeff","pvals","conf_lower","conf_higher"]]
        return results_df
    

提交回复
热议问题