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.
这就是我的变通办法。
更多回答
我是一名优秀的程序员,十分优秀!