Skip to content

Kernelreg and fit #4873

Closed
Closed

Description

@visitor54

The KernelReg works OK. See the example below:

index=range(4,100)
index1=[i for i in range(4,100)]
print(index1)

def f(x):
return x*x

values=list(map(f,index1))
print(values)

#now regress value against

kr = KernelReg(values, index_a, var_type='c', bw=[12.5,1.])

kr_pts = kr.fit([index])

But the fit function after the reg throws the following IndexError message:

Traceback (most recent call last):

File "", line 1, in
kr_pts = kr.fit(index_a)

File "/anaconda3/lib/python3.6/site-packages/statsmodels/nonparametric/kernel_regression.py", line 370, in fit
data_predict=data_predict[i, :])

File "/anaconda3/lib/python3.6/site-packages/statsmodels/nonparametric/kernel_regression.py", line 154, in _est_loc_linear
tosum=False) / float(nobs)

File "/anaconda3/lib/python3.6/site-packages/statsmodels/nonparametric/_kernel_base.py", line 513, in gpke
dens = Kval.prod(axis=1) / np.prod(bw[iscontinuous])

IndexError: boolean index did not match indexed array along dimension 0; dimension is 2 but corresponding boolean dimension is 1

The function was working OK previously. For some reason, it is no longer working.

Activity

  1. josef-pkt commented on Aug 10, 2018

    @josef-pkt
    Member

    This sounds like a numpy incompatibility.

    Which version of numpy and of statsmodels are you using?
    Most likely it is fixed in 0.9.0 or in master.

  2. visitor54 commented on Aug 11, 2018

    @visitor54
    Author
  3. josef-pkt commented on Aug 11, 2018

    @josef-pkt
    Member

    temporarily prio-high

    I don't have time to check this right now, but it needs to be checked before the next release.
    KernelReg unit test coverage is not as good as it is supposed to be. So I wouldn't rely on seeing a test failure if this is not yet fixed

  4. added this to the 0.10 milestone on Sep 9, 2018
  5. AmazingAbhi commented on May 27, 2019

    @AmazingAbhi

    Hi, I am facing the same issue. Could you please tell me how this can be fixed. I have statsmodels 0.9.0 and numpy 1.15.4.

  6. visitor54 commented on Jul 4, 2019

    @visitor54
    Author

    The bug is still not fixed in 0.10

  7. visitor54 commented on Jul 4, 2019

    @visitor54
    Author

    Need some work around or other pakcages

  8. kshedden commented on Jul 5, 2019

    @kshedden
    Contributor

    Please provide a reproducible example. The code fragments above contain undefined variables.

  9. visitor54 commented on Jul 6, 2019

    @visitor54
    Author

    Sorry. Just found that the version of package tested was 0.9.0. Kernel regression is now working for version 0.10.0. The weight bw now required to be fully specified. See example below.

    bw_1=np.full((1, 5), .5)
    bw_1

    index1=[1, 1.2, 3.2, 4, 5.1]
    values=[23, 17, 12, 27, 8]
    #values=list(map(f,index1))
    print(values)

    kr = KernelReg(values, index1, var_type='c', bw=bw_1)

    print(values)
    print(index1)
    print([index1])
    kr_pts = kr.fit([index1])

    type(index1)
    fig, ax = plt.subplots()
    #plot sine wave
    ax.plot(index1, kr_pts[0], label = "K Estimate")
    kr_pts[0]

    ax.plot(index1, values, label = "Y")

    ax.set(xlabel='X', ylabel='Y',
    title='Kernel reg')
    #ax.grid()

    #show the legend
    plt.legend()
    plt.show()

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions