SoftwareAG/nyoka

Always getting "'DataFrame' object has no attribute 'name'" upon trying to export.

Slereah opened this issue · 2 comments

Upon trying to use Nyoka to export some SARIMAX model to PMML in some project, I always end up with the same error, roughly something like

    ArimaToPMML(data, model, fit_model, path)
  File "/home/slereah/miniconda3/lib/python3.6/site-packages/nyoka/statsmodels/arima.py", line 175, in __init__
    ExportToPMML(model_name = model_name, arima_obj = sarimax_obj)
  File "/home/slereah/miniconda3/lib/python3.6/site-packages/nyoka/statsmodels/arima.py", line 28, in ExportToPMML
    DataField = get_data_field_objs(time_series_data)),
  File "/home/slereah/miniconda3/lib/python3.6/site-packages/nyoka/statsmodels/arima.py", line 150, in get_data_field_objs
    ts_name = ts_data.name
  File "/home/slereah/miniconda3/lib/python3.6/site-packages/pandas/core/generic.py", line 3614, in __getattr__
    return object.__getattribute__(self, name)
AttributeError: 'DataFrame' object has no attribute 'name'

I have tried the examples given for SARIMAX which work perfectly fine, but I have been unable to find the root cause for this error. I managed to reduce the code for the error to the following :


from statsmodels.tsa.statespace import sarimax
from nyoka import ArimaToPMML
import pandas as pd
import numpy as np

data = pd.read_csv('~/test.csv', index_col = 0)
labels = pd.read_csv('~/test2.csv', index_col = 0)
path = '~/pmmlsarimax.pmml'

model = sarimax.SARIMAX(
	endog=pd.DataFrame(data=labels),
	exog=pd.DataFrame(data=data),
	order=(1,0,0),
	seasonal_order=(0,0,0,0),
	trend='t',
	enforce_stationarity=True)
fit_model = model.fit(disp=False, maxiter=200)

ArimaToPMML(data, model, fit_model, path)

I have tried a few variations, trying to change column names or indexes, but so far nothing seems to work, or simply give different errors. The two data files are of the following form. For test.csv :

t,scaled_imputed_f2_t,ohe_label_2_t,ohe_label_3_t,ohe_label_1_t,scaled_imputed_ts_t,scaled_imputed_f1_t,ohe_label_0_t,scaled_imputed_f3_t
0,1.7320464849472046,1.0,1.0,1.0,-1.7320218086242676,-0.36193081736564636,1.0,1.7320464849472046

And for test2.csv :

,f1
0,1.087748646736145

Each being a few thousand lines long so I'll skip the full data. Where does this error come from?

Hi @Slereah , thanks for your feedback. The exporter is expecting the endog data for time_series_data parameter. Could you please try to send the endog data to the exporter as,
ArimaToPmml(labels, model, fit_model, path)

That was indeed the issue, thanks.