Closed z7ye closed 1 year ago
I could not replicate your issue. I updated your example to make it work. The main issues were the fact the model was not trained before being converted and the second argument missing in to_onnx
which tells the converting library the input type of the model.
import numpy
from sklearn.model_selection import train_test_split
from sklearn.datasets import make_classification, make_regression
import shutil
import xgboost as xgb
import onnx
import onnxruntime as rt
import numpy as np
from sklearn.datasets import load_iris
from sklearn.pipeline import Pipeline
from sklearn.preprocessing import StandardScaler
from xgboost import XGBClassifier
from skl2onnx.common.shape_calculator import (
calculate_linear_classifier_output_shapes,
calculate_linear_regressor_output_shapes,
)
from skl2onnx import to_onnx, update_registered_converter
from onnxmltools.convert.xgboost.operator_converters.XGBoost import (
convert_xgboost)
data = load_iris()
X_iris = data.data[:, :2]
y_iris = data.target
ind = np.arange(X_iris.shape[0])
np.random.shuffle(ind)
X_iris = X_iris[ind, :].copy()
y_iris = y_iris[ind].copy()
pipe = Pipeline([('scaler', StandardScaler()),
('xgbc', XGBClassifier(n_estimators=3))])
pipe.fit(X_iris, y_iris)
update_registered_converter(
xgb.XGBClassifier,
"XGBoostXGBClassifier",
calculate_linear_classifier_output_shapes,
convert_xgboost,
options={"nocl": [True, False], "zipmap": [True, False]},
)
to_onnx(pipe, X_iris[:1].astype(numpy.float32))
@z7ye Hi, we will close this issue if you don't have any concern.
gives this error
ValueError: Unable to create node 'TreeEnsembleClassifier' with name='TreeEnsembleClassifier'.