gpt4 book ai didi

How to solve Feature name error while converting an XGBClassifier model to ONNX?(如何解决将XGB分类器模型转换为ONNX时的特征名称错误?)

转载 作者:bug小助手 更新时间:2023-10-25 09:15:11 27 4
gpt4 key购买 nike



I trained an XGBClassifier model, and now I want to convert it to an ONNX format. it should be straight forward using this code:

我训练了一个XGB分类器模型,现在我想将它转换为ONNX格式。使用下面的代码应该是直接的:


import onnxmltools 
from skl2onnx.common.data_types import FloatTensorType

initial_types = [('float_input', FloatTensorType([None, X_train.shape[1]]))]

xgb_onnx = onnxmltools.convert_xgboost(xgb.xgb_category_cls, initial_types=initial_types)
onnxmltools.utils.save_model(xgb_onnx , 'xgb_onnx .onnx')

However, I get this error which is related to one of my features name:

但是,我收到这个错误,它与我的一个功能名称有关:


     77                     feature_id = int(float(feature_id))
78 except ValueError:
---> 79 raise RuntimeError(
80 "Unable to interpret '{0}', feature "
81 "names should follow pattern 'f%d'.".format(

RuntimeError: Unable to interpret 'state', feature names should follow pattern 'f%d'.

I am not sure what I did wrong.

我不知道我做错了什么。


更多回答
优秀答案推荐

I was able to mitigate the error by renaming the feature names to the following form:

我能够通过将特性名称重命名为以下形式来减轻错误:


f0, f1, f2, ....., fn

That was my workaround.

这就是我的变通办法。


更多回答

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com