onnx / sklearn-onnx

Convert scikit-learn models and pipelines to ONNX
Apache License 2.0
552 stars 103 forks source link

Inverse transform of preprocessors #765

Open Swopper050 opened 3 years ago

Swopper050 commented 3 years ago

Hi! Love the package.

Currently I am trying to convert a simple StandardScaler to ONNX using this package, but I also require the inverse transform (I recon these should be 2 seperate .onnx models), what is currently the best way to do this?

One can maybe (?) manually inverse the coefficients of the StandardScaler or something to create a new scaler, but it would feel a bit hacky.

Thanks in advance!

xadupre commented 3 years ago

It seems a bit hacky but it would work. Do you need the inverse transform on one transformer or is it a whole pipeline you need to inverse?

Swopper050 commented 3 years ago

In my use case it is simply the inverse transform of one transformer.

My application, related to HVAC systems, transforms the data into the preprocessed domain, performs regression and transforms and then I want to inverse the prediction to interpret them and build logic around them, i.e. bringing them back to the temperature domain.

Right now I have written a function which calculates the inverse coefficients of the StandardScaler (and one for MinMaxScaler) and it does work, but it is not my proudest piece of code ;)

Furthermore I would argue that applications that perform regression in a preprocessed domain would always have to be inversed back, so it might be a desirable functionality.

xadupre commented 2 years ago

So you would like to get a way to get the returned values by method inverse_transform.

Swopper050 commented 2 years ago

Yes exactly!