简体   繁体   English

Catboost:如何将 cat_features 传递给 Python 中保存的模型?

[英]Catboost: how do I pass cat_features to a saved model in Python?

I have this pre-trained saved model, where I informed my categorical features, and it's working fine if I predict right after training.我有这个预先训练好的保存模型,我在其中告知了我的分类特征,如果我在训练后立即进行预测,它就可以正常工作。 Now I wanna use it again in another context but I don't know how to properly inform the categorical features.现在我想在另一个上下文中再次使用它,但我不知道如何正确地告知分类特征。 I tried this:我试过这个:

model = CatBoostClassifier(cat_features=var_categ)  
model.load_model('catmod.cat')

but when I try to predict:但是当我尝试预测时:

modelo.predict(base)

I get this error:我收到此错误:

CatBoostError: features data: pandas.DataFrame column 'cod_var1' has dtype 'category' but is not in  cat_features list

Yes, I double checked the column is in var_categ.是的,我仔细检查了该列是否在 var_categ 中。

First of all, you don't need to specify catboost classifier cat_features because the model already has this information from load_model.首先,你不需要指定 catboost 分类器 cat_features,因为模型已经有来自 load_model 的这个信息。

I would guess from your error that when you use predict on the new data set, your features shifted by 1 location thus giving you the error.我会从你的错误中猜测,当你在新数据集上使用 predict 时,你的特征移动了 1 个位置,从而给你错误。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM