SoftwareAG/nyoka

The SARIMAX to PMML function seems to call on fields that do not exist.

Closed this issue · 5 comments

Upon calling the ArimaToPMML function on some SARIMAX and SARIMAXResults objects, the method keeps on calling fields in those objects which do not seem to exist, such as k_ar or k_ma in SARIMAXResults (they do seem to exist under specification["k_ar"] and specification["k_ma"]), or method for SARIMAX. The version of statsmodels that I use seem to be the same one used by the library, 0.9.0.

What is the reason for those discrepancies?

Hi @Slereah What is the error message you are seeing? and what is the (p,d,q)(P,D,Q,S) order used ?

It is currently done over a test of various values for the parameters, so as it only goes through the first iteration, the values are simply 0 for everything.

Here's the basic error I get if I do not prepare any of the objects :

Traceback (most recent call last):
  File "test.py", line 17, in <module>
    fv.export_model("Beep", "~", "/home/slereah", "-Xmx2g")
  File "/home/slereah/prescience/prescience/pytesla/pytesla/cross_validation/forecast_validator.py", line 117, in export_model
    java_options
  File "/home/slereah/prescience/prescience/pytesla/pytesla/cross_validation/cross_validator.py", line 215, in export_model
    java_options
  File "/home/slereah/prescience/prescience/pytesla/pytesla/cross_validation/cross_validator.py", line 228, in _export_estimator
    java_options=java_options)
  File "/home/slereah/prescience/prescience/pytesla/pytesla/estimator/sarimax_estimator.py", line 73, in export
    ArimaToPMML(self.data.iloc[0], model, fitModel, path)
  File "/home/slereah/prescience/prescience/venv/lib/python3.6/site-packages/nyoka/statsmodels/arima.py", line 131, in __init__
    ARIMA=get_arima_obj(model_obj, results_obj)
  File "/home/slereah/prescience/prescience/venv/lib/python3.6/site-packages/nyoka/statsmodels/arima.py", line 82, in get_arima_obj
    p = sm_results._results.k_ar
AttributeError: 'SARIMAXResults' object has no attribute 'k_ar'

If I add manually the values of k_ar and k_ma (as those are easy to find, they are part of specification), using this

fitModel._results.k_ar = fitModel._results.specification["k_ar"]
fitModel._results.k_ma = fitModel._results.specification["k_ma"]

The error becomes :

Traceback (most recent call last):
  File "test.py", line 17, in <module>
    fv.export_model("Beep", "~", "/home/slereah", "-Xmx2g")
  File "/home/slereah/prescience/prescience/pytesla/pytesla/cross_validation/forecast_validator.py", line 117, in export_model
    java_options
  File "/home/slereah/prescience/prescience/pytesla/pytesla/cross_validation/cross_validator.py", line 215, in export_model
    java_options
  File "/home/slereah/prescience/prescience/pytesla/pytesla/cross_validation/cross_validator.py", line 228, in _export_estimator
    java_options=java_options)
  File "/home/slereah/prescience/prescience/pytesla/pytesla/estimator/sarimax_estimator.py", line 73, in export
    ArimaToPMML(self.data.iloc[0], model, fitModel, path)
  File "/home/slereah/prescience/prescience/venv/lib/python3.6/site-packages/nyoka/statsmodels/arima.py", line 131, in __init__
    ARIMA=get_arima_obj(model_obj, results_obj)
  File "/home/slereah/prescience/prescience/venv/lib/python3.6/site-packages/nyoka/statsmodels/arima.py", line 88, in get_arima_obj
    if sm_model.method == 'css':
AttributeError: 'SARIMAX' object has no attribute 'method'

For which I cannot find the equivalent object in the file. Putting it simply None as the method, the error becomes

Traceback (most recent call last):
  File "test.py", line 17, in <module>
    fv.export_model("Beep", "~", "/home/slereah", "-Xmx2g")
  File "/home/slereah/prescience/prescience/pytesla/pytesla/cross_validation/forecast_validator.py", line 117, in export_model
    java_options
  File "/home/slereah/prescience/prescience/pytesla/pytesla/cross_validation/cross_validator.py", line 215, in export_model
    java_options
  File "/home/slereah/prescience/prescience/pytesla/pytesla/cross_validation/cross_validator.py", line 228, in _export_estimator
    java_options=java_options)
  File "/home/slereah/prescience/prescience/pytesla/pytesla/estimator/sarimax_estimator.py", line 73, in export
    ArimaToPMML(self.data.iloc[0], model, fitModel, path)
  File "/home/slereah/prescience/prescience/venv/lib/python3.6/site-packages/nyoka/statsmodels/arima.py", line 131, in __init__
    ARIMA=get_arima_obj(model_obj, results_obj)
  File "/home/slereah/prescience/prescience/venv/lib/python3.6/site-packages/nyoka/statsmodels/arima.py", line 96, in get_arima_obj
    content_value = ' '.join([str(i) for i in sm_results._results.arparams])
  File "/home/slereah/prescience/prescience/venv/lib/python3.6/site-packages/statsmodels/tools/decorators.py", line 97, in __get__
    _cachedval = self.fget(obj)
  File "/home/slereah/prescience/prescience/venv/lib/python3.6/site-packages/statsmodels/tsa/statespace/sarimax.py", line 1848, in arparams
    return self._params_ar
AttributeError: 'SARIMAXResults' object has no attribute '_params_ar'

Hi @Slereah The version of nyoka which you have installed in your machine doesn't support Seasonal ARIMA.
Since the development is still in progress, currently we have not registered
the latest version of nyoka to PyPi.
However, you can install the latest version directly from github using the below command

pip install --user --upgrade git+https://github.com/nyoka-pmml/nyoka.git

and it will resolve your issue

Comment here for further discussion.

Thank you.

Updating it thusly does not seem to do anything :

Traceback (most recent call last):
  File "test.py", line 17, in <module>
    fv.export_model("Beep", "~", "/home/slereah", "-Xmx2g")
  File "/home/slereah/prescience/prescience/pytesla/pytesla/cross_validation/forecast_validator.py", line 117, in export_model
    java_options
  File "/home/slereah/prescience/prescience/pytesla/pytesla/cross_validation/cross_validator.py", line 215, in export_model
    java_options
  File "/home/slereah/prescience/prescience/pytesla/pytesla/cross_validation/cross_validator.py", line 228, in _export_estimator
    java_options=java_options)
  File "/home/slereah/prescience/prescience/pytesla/pytesla/estimator/sarimax_estimator.py", line 73, in export
    ArimaToPMML(self.data.iloc[0], model, fitModel, path)
  File "/home/slereah/prescience/prescience/venv/lib/python3.6/site-packages/nyoka/statsmodels/arima.py", line 131, in __init__
    ARIMA=get_arima_obj(model_obj, results_obj)
  File "/home/slereah/prescience/prescience/venv/lib/python3.6/site-packages/nyoka/statsmodels/arima.py", line 82, in get_arima_obj
    p = sm_results._results.k_ar
AttributeError: 'SARIMAXResults' object has no attribute 'k_ar'

The problem seems to stem from the fact that the method goes to get_arima_obj, despite the two arguments being SARIMAX objects. To be specific, the model_obj and results_obj are :

<statsmodels.tsa.statespace.sarimax.SARIMAX object at 0x7f4c88daed30>
<statsmodels.tsa.statespace.sarimax.SARIMAXResultsWrapper object at 0x7f4c88e0ccc0>

But despite this the method seems to treat them as ARIMA objects.

Hi, @Slereah, In the error message , i can see that - its still using older version of nyoka. If you are using Jupyter notebook, please restart the kernal and run the cells after upgrading to latest version of nyoka ( it will import updated nyoka library )