Closed marinagre-px closed 4 years ago
That's a bug. In the mean time, can you try with the following option?
convert_sklearn(..., options={KNeighborsClassifier: {'optim': 'cdist'}})
It replaces the part which fails by an operator cdist (faster but this operator is the official onnx specification).
I think I'll need the version of every package as I can't replicate the issue. Here is my code:
def test_model_knn_iris_classifier_multi_reg_pipeline(self):
iris = datasets.load_iris()
X = iris.data.astype(numpy.float32)
y = iris.target.astype(numpy.float32)
#y = numpy.vstack([y, 1 - y, y + 10]).T
knn = KNeighborsClassifier(
n_neighbors=5, weights='distance')
model = Pipeline(steps=[
('imputer', SimpleImputer(strategy='median')),
('scaler', StandardScaler()),
('knn', knn)])
model.fit(X[:13], y[:13])
onx = to_onnx(model, X[:1],
# options={id(model): {'optim': 'cdist'}},
target_opset=TARGET_OPSET)
dump_data_and_model(
X.astype(numpy.float32)[:7],
model, onx, methods=["predict", "predict_proba"],
basename="SklearnKNeighborsClassifierMImp")
Thank you for quick response! These are the versions: numpy: 1.18.4 scikit-learn: 0.23.1 onnx: 1.7.0 onnxruntime: 1.3.0 skl2onnx: 1.6.1 python: 3.8
I suggest trying with the version of skl2onnx from master branch or this one released on github. There were so many changes since, I tried with this one and it seems fixed.
That's a bug. In the mean time, can you try with the following option?
convert_sklearn(..., options={KNeighborsClassifier: {'optim': 'cdist'}})
It replaces the part which fails by an operator cdist (faster but this operator is the official onnx specification).
Thank you, this worked
Also using version 1.7.0 without the options worked. Thanks
When converting KNN Classifier with numeric features, i.e.
AND
the following error is thrown:
If using LinearRegression classifier, it works