BentoML - Seving a CatBoostClassifier with cat_features

122 views Asked by At

I am trying to create a BentoML service for a CatBoostClassifier model that was trained using a column as a categorical feature. If i save the model and I try to make some predictions with the saved model (not as a BentoML service) all works as expected, but when I create the service using BentML I get an error

_catboost.CatBoostError: Bad value for num_feature[non_default_doc_idx=0,feature_idx=2]="Tertiary": Cannot convert 'b'Tertiary'' to float

The value is found in a column named 'road_type' and the model was trained using 'object' as the data type for the column.

If I try to give a float or an integer for the 'road_type' column I get the following error

_catboost.CatBoostError: catboost/libs/data/model_dataset_compatibility.cpp:53: Feature road_type is Categorical in model but marked different in the dataset

If someone has encountered the same issue and found a solution I would appreciate it. Thanks!

I have tried different approaches for saving the model or loading the model but unfortunately it did not worked.

1

There are 1 answers

0
Cristian Corches On BEST ANSWER

You can try to explicitly pass the cat_features to the bentoml runner. It would be something like this:

from catboost import Pool

runner = bentoml.catboost.get("bentoml_catboost_model:latest").to_runner()

cat_features = [2] # specify your cat_features indexes
prediction = runner.predict.run(Pool(input_data, cat_features=cat_features))