How to extract a particular value from the OLS-summary in Pandas?

后端 未结 2 1513
孤独总比滥情好
孤独总比滥情好 2021-01-12 02:11

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

相关标签:
2条回答
  • 2021-01-12 02:32

    try:

    print model.r2
    

    for example:

    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
    

    Docs: http://statsmodels.sourceforge.net/stable/index.html

    0 讨论(0)
  • 2021-01-12 02:39

    Docs handling the results of the regression - this will allow you to extract a number of values from your regression results:

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

    In the case of r-squared use:

    # retrieving model's r-squared value
    model.rsquared
    

    and in the case of p-values use:

    # return p-values and corresponding coefficients in model
    model.pvalues
    

    For more parameters (fvalues ess) please refer to the doc

    0 讨论(0)
提交回复
热议问题