How to extract the regression coefficient from statsmodels.api?

前端 未结 3 892
余生分开走
余生分开走 2021-02-07 05:34
 result = sm.OLS(gold_lookback, silver_lookback ).fit()

After I get the result, how can I get the coefficient and the constant?

In other words,

3条回答
  •  悲哀的现实
    2021-02-07 06:05

    Cribbing from this answer Converting statsmodels summary object to Pandas Dataframe, it seems that the result.summary() is a set of tables, which you can export as html and then use Pandas to convert to a dataframe, which will allow you to directly index the values you want.

    So, for your case (putting the answer from the above link into one line):

    df = pd.read_html(result.summary().tables[1].as_html(),header=0,index_col=0)[0]
    

    And then

    a=df['coef'].values[1]
    c=df['coef'].values[0]
    

提交回复
热议问题