简体   繁体   中英

Outputting a Scikit Learn OLS report

I'm running OLS multivariate regression on a bunch of data subsets.

I'm currently using this to print out the results inside my Jupiter Python Notebook:

est = sm.OLS(y.astype(float), df_new.astype(float),hasconst=True).fit()
print (est.summary())

I would like to save each summary to a .csvor .xcl in some sort of orderly format. Right now, copy-paste does not work-there is no standard delimiter. Any tips on programmatic ways to output each summary?

I believe you meant to say statsmodel in this case and not sklearn. Nonetheless, each statistic is actually stored as an attribute of the fitted estimator. It'd probably be nicer to have the information flattened out, but that functionality doesn't exist (that I am aware of). For now, you can programmatically pull this information and write them to a csv using your favorite python 'to_csv' library.

Here's some example values that show up in the summary:

# Some first table values
est.nobs, est.df_resid, est.rsquared, est.rsquared_adj, est.fvalue, est.f_pvalue, est.aic, est.bic 
est.k_constant, 

# Some second table values
est.tvalues, est.pvalues

# All third table values
est.diagn

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM