cat boost 功能在训练数据中具有"分类类型",但在测试数据集中具有'Float'类型



我正在使用catboost分类器,我有一个训练数据集和一个验证数据集。每个数据集都有相同的5列,并且有一个名为"colC"的列是分类的(列"colC"的格式为int(。我测试了数据帧,在"colC"列中,两个数据帧的数据类型相同。

当我执行下一个代码时,我得到了一个错误:

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

错误是下一个:

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

原因可能是什么?

对于其他看到这篇文章的人来说:当我遇到这个问题时,我通过在Pool中指定cat_features列表以及fit来解决它。

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

我认为使用to_categorical方法可以解决这个问题。

例如:

from keras.utils import to_categorical
y_train = to_categorical(y_train, num_classes)
y_test = to_categorical(y_test, num_classes)

最新更新