cat boost Feature has 'Categorical type in training data but 'Float' type in test dataset

Viewed 544

I am working with catboostclassifier, and I have a training dataset and a validation dataset. Each dataset have the same 5 columns, and there is one column named 'colC' that is categorical (column 'colC' is formatted as int). I tested the dataframes and in the 'colC' column has the same data type in both dataframes.

When i executing the next code I got an error:

val_pool = Pool(X_validation, y_validation)

estimator.fit(X_train, y_train, eval_set = val_pool, sample_weight = sample_weights, cat_features = ['colC'])

The error is the next:

catboost/libs/data/features_layout.cpp:391: Feature #3 has 'Categorical' type in training data, but 'Float' type in test dataset #0

Which can be the reason?

2 Answers

For anyone else who comes across this post: I managed to solve this issue when I encountered it by specifying the cat_features list in Pool as well as fit.

val_pool = Pool(X_validation, y_validation, cat_features = ['colC'])

I think the problem could be solved using to_categorical method.

For instance:

from keras.utils import to_categorical

y_train = to_categorical(y_train, num_classes)
y_test = to_categorical(y_test, num_classes)
Related