Coverage for mlprodict/onnx_conv/validate_scenarios.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 Scenario for additional converters.
4"""
5from lightgbm import LGBMRegressor, LGBMClassifier
6from xgboost import XGBRegressor, XGBClassifier
9def find_suitable_problem(model):
10 """
11 Defines suitables problems for additional converters.
13 .. runpython::
14 :showcode:
15 :warningout: DeprecationWarning
16 :rst:
18 from mlprodict.onnx_conv.validate_scenarios import find_suitable_problem
19 from mlprodict.onnxrt.validate.validate_helper import sklearn_operators
20 from pyquickhelper.pandashelper import df2rst
21 from pandas import DataFrame
22 res = sklearn_operators(extended=True)
23 res = [_ for _ in res if _['package'] != 'sklearn']
24 rows = []
25 for model in res:
26 name = model['name']
27 row = dict(name=name)
28 try:
29 prob = find_suitable_problem(model['cl'])
30 if prob is None:
31 continue
32 for p in prob:
33 row[p] = 'X'
34 except RuntimeError:
35 pass
36 rows.append(row)
37 df = DataFrame(rows).set_index('name')
38 df = df.sort_index()
39 print(df2rst(df, index=True))
41 """
42 def _internal(model):
43 # Exceptions
44 if model in {LGBMRegressor, XGBRegressor}:
45 return ['b-reg', '~b-reg-64']
47 if model in {LGBMClassifier, XGBClassifier}:
48 return ['b-cl', 'm-cl', '~b-cl-64']
50 # Not in this list
51 return None
53 res = _internal(model)
54 return res
57def build_custom_scenarios():
58 """
59 Defines parameters values for some operators.
61 .. runpython::
62 :showcode:
63 :warningout: DeprecationWarning
65 from mlprodict.onnx_conv.validate_scenarios import build_custom_scenarios
66 import pprint
67 pprint.pprint(build_custom_scenarios())
68 """
69 return {
70 # scenarios
71 LGBMClassifier: [
72 ('default', {'n_estimators': 5}, {'conv_options': [
73 {LGBMClassifier: {'zipmap': False}}]}),
74 ],
75 LGBMRegressor: [
76 ('default', {'n_estimators': 100}),
77 ],
78 XGBClassifier: [
79 ('default', {'n_estimators': 5}, {'conv_options': [
80 {XGBClassifier: {'zipmap': False}}]}),
81 ],
82 XGBRegressor: [
83 ('default', {'n_estimators': 100}),
84 ],
85 }