如何从 pandas 的OLS摘要中提取特定值? [英] How to extract a particular value from the OLS-summary in Pandas?

查看:173
本文介绍了如何从 pandas 的OLS摘要中提取特定值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以从熊猫线性回归的摘要中获得其他值(目前,我仅知道一种获取beta和截距的方法)?我需要获得R平方. 这是从手册中摘录的:

is it possible to get other values (currently I know only a way to get beta and intercept) from the summary of linear regression in pandas? I need to get R-squared. Here is an extraction from manual:

In [244]: model = ols(y=rets['AAPL'], x=rets.ix[:, ['GOOG']])

In [245]: model
Out[245]: 
-------------------------Summary of Regression Analysis---------------------   ----
Formula: Y ~ <GOOG> + <intercept>
Number of Observations:         756
Number of Degrees of Freedom:   2
R-squared:         0.2814
Adj R-squared:     0.2805
Rmse:              0.0147
F-stat (1, 754):   295.2873, p-value:     0.0000
Degrees of Freedom: model 1, resid 754
-----------------------Summary of Estimated Coefficients------------------------
      Variable       Coef    Std Err     t-stat    p-value    CI 2.5%   CI 97.5%
--------------------------------------------------------------------------------
      GOOG     0.5442     0.0317      17.18     0.0000     0.4822     0.6063
 intercept     0.0011     0.0005       2.14     0.0327     0.0001     0.0022
---------------------------------End of Summary---------------------------------

谢谢

推荐答案

尝试:

print model.r2

例如:

import pandas as pd
from pandas import Panel
from pandas.io.data import DataReader
import scikits.statsmodels.api as sm

symbols = ['MSFT', 'GOOG', 'AAPL']

data = dict((sym, DataReader(sym, "yahoo")) for sym in symbols)

panel = Panel(data).swapaxes('items', 'minor')

close_px = panel['Close']

# convert closing prices to returns
rets = close_px / close_px.shift(1) - 1
model = pd.ols(y=rets['AAPL'], x=rets.ix[:, ['GOOG']])
print model.r2

文档: http://statsmodels.sourceforge.net/stable/index.html

这篇关于如何从 pandas 的OLS摘要中提取特定值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆