RJT1990 / pyflux

Open source time series library for Python
BSD 3-Clause "New" or "Revised" License
2.11k stars 240 forks source link

AttributeError: 'str' object has no attribute 'X' #104

Closed efkag closed 7 years ago

efkag commented 7 years ago

GP-NARX model

Hi I am using the narx model and the following error is thrown when I try to propose the model.

Traceback (most recent call last):
  File "/home/efkag/Desktop/BTBSimulator/SimulatorPackage/Simulator.py", line 163, in <module>
    model = pf.GPNARX(data=data_arr, ar=2, kernel='RQ', integ=4, target=[0, 1])
  File "/usr/local/lib/python3.5/dist-packages/pyflux/gpnarx/gpnarx.py", line 84, in __init__
    self.kernel.X = self.X().T
AttributeError: 'str' object has no attribute 'X'

I am using Python 3.5. I tried changing the input from NumPy to Pandas Data Frame and changing the type of the kernel but nothing seems to work. The IDE identifies the problem to be in line 84 in the library file gpnarx.py. screenshot from 2017-07-01 17-18-28

Please help I don't know how to fix this.

RJT1990 commented 7 years ago

Hi - the short answer on this is that the GP part of the package was never really finished, so I wouldn't recommend using it. Should give PyMC3 a go for this -> https://github.com/pymc-devs/pymc3.

Thanks! Ross

efkag commented 7 years ago

The problem was that I was passing in a String as shown in this part of the documentation http://www.pyflux.com/docs/gpnar.html#fit

but the parameter requires a kernel object like so:

model = pf.GPNARX(data=data, ar=4, kernel=pf.OrnsteinUhlenbeck(), integ=4, target=['Sl', 'Sr'])

Do you still recommend to not use the NARX api? I am only interested in the NARX model and not the GP part. Does the GP part afffect the NARX? If yes is there another NARX api I can use?

Thanks in advance.

RJT1990 commented 7 years ago

The NARX part is essentially twofold : creating lagged features (AR) which you can plug into any standard regression models, and the non-linear part (which again, is a choice of an algorithm which is not linear regression). You can do this with scikit-learn; alternatively if you want to stay in the probabilistic space, then I'd recommend PyMC3!

efkag commented 7 years ago

So to understand you are saying that I could train an MLP in scikit by setting up the input and output features to represent the lag that a NARX network uses.
Then to run it in a closed loop ,a.k.a predict the outputs for given inputs, I would have to predict the output for an input and then use that output as the lag for my next input prediction. Is that right?

Thank you.

RJT1990 commented 7 years ago

Yes that sounds like the right approach! You may not have to use an MLP either, can use any non-linear regression algorithm (e.g. RF, SVM, etc).