Coverage for mlprodict/onnx_conv/sklconv/transformed_target_regressor.py: 100%

14 statements  

« prev     ^ index     » next       coverage.py v7.1.0, created at 2023-02-04 02:28 +0100

1""" 

2@file 

3@brief Rewrites some of the converters implemented in 

4:epkg:`sklearn-onnx`. 

5""" 

6from sklearn.preprocessing import FunctionTransformer 

7from skl2onnx.algebra.onnx_operator import OnnxSubEstimator 

8 

9 

10def transformer_target_regressor_shape_calculator(operator): 

11 """ 

12 Rewrites the converters implemented in 

13 :epkg:`sklearn-onnx` to support custom functions 

14 implemented with :ref:`l-numpy-onnxpy`. 

15 """ 

16 input_type = operator.inputs[0].type.__class__ 

17 # same output shape as input 

18 output_type = input_type([None, None]) 

19 operator.outputs[0].type = output_type 

20 

21 

22def transformer_target_regressor_converter(scope, operator, container): 

23 """ 

24 Rewrites the converters implemented in 

25 :epkg:`sklearn-onnx` to support custom functions 

26 implemented with :ref:`l-numpy-onnxpy`. 

27 """ 

28 op = operator.raw_operator 

29 opv = container.target_opset 

30 X = operator.inputs[0] 

31 

32 Y = OnnxSubEstimator(op.regressor_, X, op_version=opv) 

33 cpy = FunctionTransformer(op.transformer_.inverse_func) 

34 Z = OnnxSubEstimator(cpy, Y, output_names=operator.outputs) 

35 Z.add_to(scope, container)