【问题标题】:what does the numpy vander function do and why use it in a regression?numpy vander 函数有什么作用,为什么在回归中使用它?
【发布时间】:2020-07-29 14:46:52
【问题描述】:

我正在尝试根据module这个module写的代码来理解协整。

但是,当我单步执行代码时,我对下面代码部分的最后一行感到困惑。我已经阅读了 vander 函数的文档,但是我真的不明白这个函数在做什么?

 def detrend(y, order):
    if order == -1:
       return y
    return OLS(y, np.vander(np.linspace(-1, 1, len(y)), order + 1)).fit().resid

【问题讨论】:

    标签: python-3.x numpy regression


    【解决方案1】:

    函数 np.vander 返回一个数组,其中第一列为 x^(N-1),第二列为 x^(N-2),依此类推。看这个例子:

    x = np.array([1, 2, 3, 5])
    N = 3
    np.vander(x, N)
    
    array([[ 1,  1,  1],
       [ 4,  2,  1],
       [ 9,  3,  1],
       [25,  5,  1]])
    

    在您的代码中 N= order+1 和 X=np.linspace(-1, 1, len(y))。 您也可以使用“increasing=True”,其中第一列为 x^(0),第二列为 x^(1),依此类推,最后列为 x^(N-1)。

    【讨论】:

      猜你喜欢
      • 2018-03-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-07-16
      • 2015-06-09
      • 2018-10-07
      • 1970-01-01
      相关资源
      最近更新 更多