Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

python sm.ols change format of summary to avoid scientific notation

I am running an ols model and I need to know all the coefficients so I can use them in my analysis. How can I display/save the coefficients in a different format than scientific notation?

model = sm.ols(formula="sales ~ product_category + quantity_bought + quantity_ordered + quantity_returned + season", data=final_email).fit()
print model.summary()

OLS Regression Results                            
==============================================================================
Dep. Variable:                sales   R-squared:                       0.974
Model:                            OLS   Adj. R-squared:                  0.938
Method:                 Least Squares   F-statistic:                     27.26
Date:                Tue, 18 Apr 2017   Prob (F-statistic):           5.39e-13
Time:                        11:43:36   Log-Likelihood:                -806.04
No. Observations:                  60   AIC:                             1682.
Df Residuals:                      25   BIC:                             1755.
Df Model:                          34                                         
Covariance Type:            nonrobust                                         
======================================================================================
                         coef    std err          t      P>|t|      [95.0% Conf. Int.]
--------------------------------------------------------------------------------------
Intercept            -2.79e+05   2.883e+05     -0.987      0.333     -8.92e+05  3.14e+05
Product_category[A]   4.343e+04   2.456e+05      0.186      0.854     -4.95e+05  5.93e+05
Product_category[B]   2.784e+05    1.23e+05      1.128      0.270     -1.68e+05  5.75e+05
quantity_bought       -74678      1.754e+05     -0.048      0.962      -3.4e+05  3.24e+05
quantity_ordered      3.543e+05   1.363e+05      1.827      0.080     -4.21e+04  7.05e+05
quantity_returned     1.285e+05   2.154e+05      0.512      0.613     -4.61e+05  7.66e+05
season               -1.983e+04   1.76e+05     -0.133      0.895     -2.69e+05  

Warnings:
[1] Standard Errors assume that the covariance matrix of the errors is correctly specified.
[2] The smallest eigenvalue is 1.19e-29. This might indicate that there are
strong multicollinearity problems or that the design matrix is singular.

This didn't help:

pd.set_option('display.float_format', lambda x: '%3.f' % x)
like image 803
jeangelj Avatar asked Dec 11 '22 11:12

jeangelj


1 Answers

So that is something that is hardcoded into the statsmodels source. But the best way to get the coefficients out would be with model.params. Take a look at the source for RegressionResults, specifically all of the attributes and that will show you how to access all of the pertinent information for you model fit.

like image 61
Grr Avatar answered Apr 30 '23 22:04

Grr