【问题标题】:Remove high residual and high leverage points in Influence Plot?移除影响图中的高残差和高杠杆点?
【发布时间】:2018-04-15 07:21:46
【问题描述】:

我正在使用波士顿房价数据进行一些线性回归。

Influence Plot,有多个高残差点和几个高杠杆点。

如何去除高残差和高杠杆点,以便重新运行线性回归模型并重新绘制影响图和 Q-Q 图?


输入:

m = ols('PRICE ~ CRIM + RM + PTRATIO',bos).fit()
print(m.summary())

截断输出:

                 coef    std err          t      P>|t|      [0.025      0.975]
Intercept     -3.3066      4.038     -0.819      0.413     -11.240       4.627
CRIM          -0.2021      0.032     -6.301      0.000      -0.265      -0.139
RM             7.3816      0.402     18.360      0.000       6.592       8.171
PTRATIO       -1.0742      0.133     -8.081      0.000      -1.335      -0.813

影响图:

QQ图:

【问题讨论】:

    标签: python plot regression linear-regression outliers


    【解决方案1】:

    在学生化残差的情况下,有经验法则将观察标记为可能的异常值:

    Studentized Residual value for any observation > |3|
    
    

    您可以使用statsmodels 库轻松找到这些观察结果。 这是一个代码,可以帮助您找到任何观察的学生化残差值的观察 > |3|

    from statsmodels.regression.linear_model import OLS
    from statsmodels.stats.outliers_influence import OLSInfluence as olsi
    import seaborn as sb
    import matplotlib.pyplot as plt
    %matplotlib inline
    
    lrmodel = OLS(y_train, x_train)
    results = lrmodel.fit()
    
    studentized_residuals = olsi(results).resid_studentized
    keep_observ_at_indx = [i for i in studentized_residuals if abs(i) > 3] # applying the above mentioned thumb rule
    leverage_pts = olsi(results).hat_matrix_diag        # this will give the array of leverage values
    sb.residplot(x = studentized_residuals, y = leverage_pts, color = 'brown')
    plt.show()
    
    

    a.) 现在,我们终于有了 studentized_residuals > 3 的索引,这些索引获取观察结果。

    b.) 据我从互联网上了解到,我认为库克的距离将帮助我们消除高杠杆点。但我不确定“太大”有多大!所以不能过多评论。以下是计算“厨师距离”的方法

    cook_dist = dict(olsi(result).cooks_distance[0])
    
    # {key(index) : value(cook's distance)}
    
    

    【讨论】:

      猜你喜欢
      • 2015-08-08
      • 2020-11-10
      • 2016-05-04
      • 2016-12-18
      • 1970-01-01
      • 2018-02-27
      • 1970-01-01
      • 2018-05-23
      • 1970-01-01
      相关资源
      最近更新 更多