Raju Natra
Raju Natra

Reputation: 11

Xgboost Signature converting categorical variable to string. Need to keep categorical variables throughout the process

As part of model logging, I observed an issue. Infer Signature is converting categorical variables into object.

I need to log_model and register with variable as categorical, This is causing model failed during inference

Before Infer_singature,  Data type is categerical:
MACHINE_SERIAL_NUMBER    category
RECIPE                   category
Year                      float64
Month                     float64
Day                       float64
dtype: object

But signature is converting category as string. This is the issue I could find this: print (signature) ['MACHINE_SERIAL_NUMBER': string (required), 'RECIPE': string (required), 'Year': double (required), 'Month': double (required), 'Day': double (required)] outputs: None params: None

input_example = pd.DataFrame([{
    'MACHINE_SERIAL_NUMBER': 'BTB0001241',
    'RECIPE': 'DECAF',
    'Year': 2024,
    'Month': 2,
    'Day': 9
}])
# Convert input_example to match training data types
input_example["MACHINE_SERIAL_NUMBER"] = input_example["MACHINE_SERIAL_NUMBER"].astype("category")
input_example["RECIPE"] = input_example["RECIPE"].astype("category")
input_example["Year"] = input_example["Year"].astype("float64")
input_example["Month"] = input_example["Month"].astype("float64")
input_example["Day"] = input_example["Day"].astype("float64")
print(input_example.dtypes)
# Infer Signature
signature = infer_signature(input_example, y_pred)

Upvotes: 1

Views: 5

Answers (0)

Related Questions