Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

to_onnx fail on sklearn.linear_model.ElasticNet for 12 inputs #1104

Open
bardout opened this issue Jun 12, 2024 · 0 comments
Open

to_onnx fail on sklearn.linear_model.ElasticNet for 12 inputs #1104

bardout opened this issue Jun 12, 2024 · 0 comments
Assignees

Comments

@bardout
Copy link

bardout commented Jun 12, 2024

Summary

after fit on a ElasticNet on a regression, convert onnx, based on test_x, default parameters, fail to convert_operators @ iteration 1 - n_vars=0 n_ops=1, for operator SklearnLinearRegressor : at most 1 input(s) is(are) supported but we got 12 input(s). Search issue "LinearRegressor" did not help

expected results

I expect to convert the model to use on onnx_engine. Maybe there is a mistake in the train or the convert, the code is naive.

data

from kaggle: the wine-quality-dataset, tabular data, 12 input variables (float, based on physicochemical tests), one Output variable (based on sensory data): the quality (score between 0 and 10 with 2 decimals).

code

import warnings
import pandas as pd
import numpy as np
from sklearn.model_selection import train_test_split
from sklearn.linear_model import ElasticNet
warnings.filterwarnings("ignore")
np.random.seed(40)

# Read the wine-quality csv file (make sure you're running this from the root of MLflow!)
data = pd.read_csv("WineQT.csv"))

# Split the data into training and test sets. (0.75, 0.25) split.
train, test = train_test_split(data)

# The predicted column is "quality" which is a scalar from [3, 9]
train_x = train.drop(["quality"], axis=1)
test_x = test.drop(["quality"], axis=1)
train_y = train[["quality"]]
test_y = test[["quality"]]
lr = ElasticNet(alpha=0.2, l1_ratio=0.2, random_state=42)
lr.fit(train_x, train_y)

import skl2onnx
try:
    print('--- convert onnx, based on test_x, default parameters ---')
    onx = skl2onnx.to_onnx(lr, test_x, model_optim=True, verbose=3) # optional parameters TBD
    with open("D00_DATA\D03_MODEL\model.onnx", "wb") as f:
        f.write(onx.SerializeToString())
except Exception as exc: # Error  to_onnx or IO
    print(exc)

log verbose=3

[to_onnx] initial_types=[('fixed acidity', DoubleTensorType(shape=[None, 1])), ('volatile acidity', DoubleTensorType(shape=[None, 1])), ('citric acid', DoubleTensorType(shape=[None, 1])), ('residual sugar', DoubleTensorType(shape=[None, 1])), ('chlorides', DoubleTensorType(shape=[None, 1])), ('free sulfur dioxide', DoubleTensorType(shape=[None, 1])), ('total sulfur dioxide', DoubleTensorType(shape=[None, 1])), ('density', DoubleTensorType(shape=[None, 1])), ('pH', DoubleTensorType(shape=[None, 1])), ('sulphates', DoubleTensorType(shape=[None, 1])), ('alcohol', DoubleTensorType(shape=[None, 1])), ('Id', Int64TensorType(shape=[None, 1]))]
[convert_sklearn] parse_sklearn_model
[convert_sklearn] convert_topology
[convert_operators] begin
[convert_operators] iteration 1 - n_vars=0 n_ops=1
For operator SklearnLinearRegressor (type: SklearnLinearRegressor), at most 1 input(s) is(are) supported but we got 12 input(s) which are ['fixed_acidity', 'volatile_acidity', 'citric_acid', 'residual_sugar', 'chlorides', 'free_sulfur_dioxide', 'total_sulfur_dioxide', 'density', 'pH', 'sulphates', 'alcohol', 'Id']
@xadupre xadupre self-assigned this Jun 21, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants