Coverage for mlprodict/npy/numpy_onnx_impl_skl.py: 100%

Shortcuts on this page

r m x   toggle line displays

j k   next/prev highlighted chunk

0   (zero) top of page

1   (one) first highlighted chunk

14 statements  

1""" 

2@file 

3@brief :epkg:`numpy` functions implemented with :epkg:`onnx`. 

4 

5.. versionadded:: 0.6 

6""" 

7from .xop_convert import OnnxSubEstimator 

8from .onnx_variable import MultiOnnxVar, OnnxVar 

9 

10 

11def linear_regression(x, *, model=None): 

12 """ 

13 Returns a linear regression converted into ONNX. 

14 

15 :param x: array, variable name, instance of :class:`OnnxVar 

16 <mlprodict.npy.onnx_variable.OnnxVar>` 

17 :param model: instance of :epkg:`sklearn:linear_model:LinearRegression` 

18 :return: instance of :class:`OnnxVar 

19 <mlprodict.npy.onnx_variable.OnnxVar>` 

20 """ 

21 return OnnxVar(model, x, op=OnnxSubEstimator) 

22 

23 

24def logistic_regression(x, *, model=None): 

25 """ 

26 Returns a logistic regression converted into ONNX, 

27 option *zipmap* is set to false. 

28 

29 :param x: array, variable name, instance of :class:`OnnxVar 

30 <mlprodict.npy.onnx_variable.OnnxVar>` 

31 :param model: instance of :epkg:`sklearn:linear_model:LinearRegression` 

32 :return: instance of :class:`MultiOnnxVar 

33 <mlprodict.npy.onnx_variable.MultiOnnxVar>`, first 

34 output is labels, second one is the probabilities 

35 """ 

36 return MultiOnnxVar(model, x, op=OnnxSubEstimator, 

37 options={'zipmap': False}) 

38 

39 

40def classifier(x, *, model=None): 

41 """ 

42 Returns any classifier from :epkg:`scikit-learn` 

43 converted into ONNX assuming a converter is registered 

44 with :epkg:`sklearn-onnx`. Option *zipmap* is set to false. 

45 

46 :param x: array, variable name, instance of :class:`OnnxVar 

47 <mlprodict.npy.onnx_variable.OnnxVar>` 

48 :param model: instance of a classifier 

49 :return: instance of :class:`MultiOnnxVar 

50 <mlprodict.npy.onnx_variable.MultiOnnxVar>`, first 

51 output is labels, second one is the probabilities 

52 """ 

53 return MultiOnnxVar(model, x, op=OnnxSubEstimator, 

54 options={'zipmap': False}) 

55 

56 

57def cluster(x, *, model=None): 

58 """ 

59 Returns any cluster from :epkg:`scikit-learn` 

60 converted into ONNX assuming a converter is registered 

61 with :epkg:`sklearn-onnx`. Option *zipmap* is set to false. 

62 

63 :param x: array, variable name, instance of :class:`OnnxVar 

64 <mlprodict.npy.onnx_variable.OnnxVar>` 

65 :param model: instance of a cluster 

66 :return: instance of :class:`MultiOnnxVar 

67 <mlprodict.npy.onnx_variable.MultiOnnxVar>`, first 

68 output is labels, second one is the probabilities 

69 """ 

70 return MultiOnnxVar(model, x, op=OnnxSubEstimator) 

71 

72 

73def regressor(x, *, model=None): 

74 """ 

75 Returns any regressor from :epkg:`scikit-learn` 

76 converted into ONNX assuming a converter is registered 

77 with :epkg:`sklearn-onnx`. 

78 

79 :param x: array, variable name, instance of :class:`OnnxVar 

80 <mlprodict.npy.onnx_variable.OnnxVar>` 

81 :param model: instance of a regressor 

82 :return: instance of :class:`OnnxVar 

83 <mlprodict.npy.onnx_variable.OnnxVar>` 

84 """ 

85 return OnnxVar(model, x, op=OnnxSubEstimator) 

86 

87 

88def transformer(x, *, model=None): 

89 """ 

90 Returns any transformer from :epkg:`scikit-learn` 

91 converted into ONNX assuming a converter is registered 

92 with :epkg:`sklearn-onnx`. 

93 

94 :param x: array, variable name, instance of :class:`OnnxVar 

95 <mlprodict.npy.onnx_variable.OnnxVar>` 

96 :param model: instance of a transformer 

97 :return: instance of :class:`OnnxVar 

98 <mlprodict.npy.onnx_variable.OnnxVar>` 

99 """ 

100 return OnnxVar(model, x, op=OnnxSubEstimator)