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
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
1"""
2@file
3@brief :epkg:`numpy` functions implemented with :epkg:`onnx`.
5.. versionadded:: 0.6
6"""
7from .xop_convert import OnnxSubEstimator
8from .onnx_variable import MultiOnnxVar, OnnxVar
11def linear_regression(x, *, model=None):
12 """
13 Returns a linear regression converted into ONNX.
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)
24def logistic_regression(x, *, model=None):
25 """
26 Returns a logistic regression converted into ONNX,
27 option *zipmap* is set to false.
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})
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.
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})
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.
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)
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`.
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)
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`.
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)