zoukankan      html  css  js  c++  java
  • 一元模型拟合

    import pandas as pd
    import statsmodels.api as sm
    # 数据的导入
    data = pd.read_table("E:\python\part 2\017\TRD_Index.txt",sep='	')
    
    # 目标数据的提取
    
    # 根据 行标签 提取数据
    sh_data = data[data['Indexcd']==1]
    sz_data = data[data.Indexcd==399106]
    # 提取 列 数据
    sh_ret = sh_data.Retindex
    sz_ret = sz_data['Retindex']
    # 索引一致化
    # print(sh_ret.index)
    # print(sz_ret.index)
    sz_ret.index = sh_ret.index
    
    # 构造回归模型
    model = sm.OLS(sh_ret,sm.add_constant(sz_ret)).fit()
    print(model.summary())

    模型结果:

    OLS Regression Results                            
    ==============================================================================
    Dep. Variable:               Retindex   R-squared:                       0.825
    Model:                            OLS   Adj. R-squared:                  0.825
    Method:                 Least Squares   F-statistic:                     5698.
    Date:                Thu, 14 Dec 2017   Prob (F-statistic):               0.00
    Time:                        19:11:39   Log-Likelihood:                 4520.3
    No. Observations:                1211   AIC:                            -9037.
    Df Residuals:                    1209   BIC:                            -9026.
    Df Model:                           1                                         
    Covariance Type:            nonrobust                                         
    ==============================================================================
                     coef    std err          t      P>|t|      [95.0% Conf. Int.]
    ------------------------------------------------------------------------------
    const         -0.0003      0.000     -1.747      0.081        -0.001  3.58e-05
    Retindex       0.7603      0.010     75.487      0.000         0.741     0.780
    ==============================================================================
    Omnibus:                      154.029   Durbin-Watson:                   1.821
    Prob(Omnibus):                  0.000   Jarque-Bera (JB):              382.039
    Skew:                           0.701   Prob(JB):                     1.10e-83
    Kurtosis:                       5.367   Cond. No.                         60.5
    ==============================================================================
    
    Warnings:
    [1] Standard Errors assume that the covariance matrix of the errors is correctly specified.
    
    Process finished with exit code 0
    1. 可以得出R的平方为:0.825,可以解释82.5%的方差。
    2. 截距项为-0.0003,p值为0.081,无法通过通过置信度为0.05的检验,可以推断该模型不含截距项,即为0.
    3. 斜率为0.7603,通过检验,显著不为0.
    4. 模型为:sh_ret = -0.0003 + 0.7603 sz_ret + e
  • 相关阅读:
    Maximum Flow Exhaustion of Paths Algorithm
    ubuntu下安装java环境
    visualbox使用(二)
    vxworks一个超级奇怪的错误(parse error before `char')
    February 4th, 2018 Week 6th Sunday
    February 3rd, 2018 Week 5th Saturday
    February 2nd, 2018 Week 5th Friday
    February 1st, 2018 Week 5th Thursday
    January 31st, 2018 Week 05th Wednesday
    January 30th, 2018 Week 05th Tuesday
  • 原文地址:https://www.cnblogs.com/hanbb/p/8039493.html
Copyright © 2011-2022 走看看