Predicting from a Converted XGboost Model to Daal4py RuntimeError: Could not convert Python object to oneDAL table

197 Views Asked by At

I have an XGBoost model trained using the Scikit XGBoostRegressor API. It is a binary classification problem. Now, I want to convert it to daal format for faster inference but I keep getting RuntimeError: Could not convert Python object to oneDAL table.

Here is my code

with open(r'xgboost-model', 'rb') as input_file:
    model = pickle.load(input_file)

import daal4py as d4p
daal_model = d4p.get_gbt_model_from_xgboost(model.get_booster()) 

predict = d4p.gbt_classification_prediction(2).compute(test2, daal_model).prediction

and I get..

---------------------------------------------------------------------------
RuntimeError                              Traceback (most recent call last)
Cell In [13], line 1
----> 1 prediction = d4p.gbt_classification_prediction(2).compute(test2, daal_model).prediction

File build/daal4py_cy.pyx:12628, in daal4py._daal4py.gbt_classification_prediction.compute()

File build/daal4py_cy.pyx:246, in daal4py._daal4py._execute_with_context.exec_func()

File build/daal4py_cy.pyx:12611, in daal4py._daal4py.gbt_classification_prediction._compute()

RuntimeError: Could not convert Python object to oneDAL table.
1

There are 1 best solutions below

0
Nikolay Petrov On

Suggest to try current version - 2023.2.1 at least - it does contain API changes to simplify it and align with XGBoost API.

import daal4py as d4p
d4p_model = d4p.mb.convert_model(xgb_model)
d4p_prediction = d4p_model.predict(test_data)

https://intelpython.github.io/daal4py/model-builders.html